home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / master / Doc / dice_libraries.doc < prev   
Text File  |  1994-02-01  |  242KB  |  8,591 lines

  1. dice/StringFunctions                                       dice/StringFunctions
  2.  
  3.     String Functions
  4.     ----------------
  5.     Name         : Description                    : Class
  6.     =============+==============================================+=======
  7.     atof         : convert string into floating point        : ANSI
  8.     -------------+----------------------------------------------+-------
  9.     atoi         : convert string into integer            : ANSI
  10.     -------------+----------------------------------------------+-------
  11.     atol         : convert string into long integer         : ANSI
  12.     -------------+----------------------------------------------+-------
  13.     isalnum      : is character alphanumeric?            : ANSI
  14.     -------------+----------------------------------------------+-------
  15.     isalpha      : is character alphabetic?             : ANSI
  16.     -------------+----------------------------------------------+-------
  17.     iscntrl      : is character a control character?        : ANSI
  18.     -------------+----------------------------------------------+-------
  19.     isdigit      : is character numeric?                : ANSI
  20.     -------------+----------------------------------------------+-------
  21.     isgraph      : is character graphic?                : ANSI
  22.     -------------+----------------------------------------------+-------
  23.     islower      : is character lower case?             : ANSI
  24.     -------------+----------------------------------------------+-------
  25.     isprint      : is character printable?                : ANSI
  26.     -------------+----------------------------------------------+-------
  27.     ispunct      : is character punctuation?            : ANSI
  28.     -------------+----------------------------------------------+-------
  29.     isspace      : is character whitespace?             : ANSI
  30.     -------------+----------------------------------------------+-------
  31.     isupper      : is character upper case                : ANSI
  32.     -------------+----------------------------------------------+-------
  33.     isxdigit     : is character hex digit                : ANSI
  34.     -------------+----------------------------------------------+-------
  35.     printf         : format output                    : ANSI
  36.     -------------+----------------------------------------------+-------
  37.     stpchr         : search for a character in a string        : UNIX
  38.     -------------+----------------------------------------------+-------
  39.     stpcpy         : string copy                    : UNIX
  40.     -------------+----------------------------------------------+-------
  41.     strbpl         : build sting pointer                : DICE
  42.     -------------+----------------------------------------------+-------
  43.     strcat         : concatenate strings                : ANSI
  44.     -------------+----------------------------------------------+-------
  45.     strchr         : find character in string             : ANSI
  46.     -------------+----------------------------------------------+-------
  47.     strcmp         : compare strings                    : ANSI
  48.     -------------+----------------------------------------------+-------
  49.     strcpy         : string copy                    : ANSI
  50.     -------------+----------------------------------------------+-------
  51.     strcspn      : scan string for a character            : ANSI
  52.     -------------+----------------------------------------------+-------
  53.     strdup         : duplicate string                 : UNIX
  54.     -------------+----------------------------------------------+-------
  55.     strerror     : return error string                : ANSI
  56.     -------------+----------------------------------------------+-------
  57.     strftime     : convert time to string                : ANSI
  58.     -------------+----------------------------------------------+-------
  59.     stricmp      : compare strings (case insensitive)        : UNIX
  60.     -------------+----------------------------------------------+-------
  61.     strins         : insert a string                    : DICE
  62.     -------------+----------------------------------------------+-------
  63.     strlen         : return length of string                : ANSI
  64.     -------------+----------------------------------------------+-------
  65.     strncat      : concatenate strings                : ANSI
  66.     -------------+----------------------------------------------+-------
  67.     strncmp      : compare strings                    : ANSI
  68.     -------------+----------------------------------------------+-------
  69.     strncpy      : string copy (length limited)            : ANSI
  70.     -------------+----------------------------------------------+-------
  71.     strnicmp     : compare strings (case insensitive, length    : ANSI
  72.              : limited)                     :
  73.     -------------+----------------------------------------------+-------
  74.     strpbrk      : find break character in string            : ANSI
  75.     -------------+----------------------------------------------+-------
  76.     strrchr      : scan string for a character (backward)        : ANSI
  77.     -------------+----------------------------------------------+-------
  78.     strspn         : span of characters in string            : ANSI
  79.     -------------+----------------------------------------------+-------
  80.     strstr         : find sub-string in string            : ANSI
  81.     -------------+----------------------------------------------+-------
  82.     strtod         : convert string to double             : ANSI
  83.     -------------+----------------------------------------------+-------
  84.     strtok         : tokenize a string                : ANSI
  85.     -------------+----------------------------------------------+-------
  86.     strtol,      : convert string to [unsigned] long        : ANSI
  87.     strtoul      :                            :
  88.     -------------+----------------------------------------------+-------
  89.     tolower      : convert character to lower case            : ANSI
  90.     -------------+----------------------------------------------+-------
  91.     toupper      : convert character to upper case            : ANSI
  92.     -------------+----------------------------------------------+-------
  93.  
  94. dice/IOFunctions,InputFunctions,OutputFunctions              dice/IO
  95.  
  96.     Input/Output Functions
  97.     ----------------------
  98.       Name       : Description                : Class
  99.       =========+============================================+==========
  100.       access   : determine if file is accessible        : UNIX
  101.       ---------+--------------------------------------------+----------
  102.       chdir    : change current directory            : UNIX
  103.       ---------+--------------------------------------------+----------
  104.       clearerr : clear error associated with file pointer    : ANSI
  105.       ---------+--------------------------------------------+----------
  106.       close    : close a file descriptor            : UNIX
  107.       ---------+--------------------------------------------+----------
  108.       creat    : create a file (obsolete)            : UNIX
  109.       ---------+--------------------------------------------+----------
  110.       dir       : directory scanning routine         : UNIX
  111.       ---------+--------------------------------------------+----------
  112.       fclose   : close a file pointer            : ANSI
  113.       ---------+--------------------------------------------+----------
  114.       fcntl    : file control of a file            : UNIX
  115.       ---------+--------------------------------------------+----------
  116.       fdopen   : associate file pointer and file descriptor : UNIX
  117.       ---------+--------------------------------------------+----------
  118.       fdtoh    : return file handle from file descriptor    : AmigaDOS
  119.       ---------+--------------------------------------------+----------
  120.       feof       : return EOF indication for file        : ANSI
  121.       ---------+--------------------------------------------+----------
  122.       ferror   : return error condition for file        : ANSI
  123.       ---------+--------------------------------------------+----------
  124.       fflush   : flush buffers to file            : ANSI
  125.       ---------+--------------------------------------------+----------
  126.       fgetc    : get a single character from a file     : ANSI
  127.       ---------+--------------------------------------------+----------
  128.       fgetpos  : get current file position            : ANSI
  129.       ---------+--------------------------------------------+----------
  130.       fgets    : get a line from a file            : ANSI
  131.       ---------+--------------------------------------------+----------
  132.       fhprintf : formatted printing to a file        : AmigaDOS
  133.       ---------+--------------------------------------------+----------
  134.       fileno   : get file descriptor from file pointer    : UNIX
  135.       ---------+--------------------------------------------+----------
  136.       fopen    : open a file                : ANSI
  137.       ---------+--------------------------------------------+----------
  138.       fprintf  : formatted output to a file         : ANSI
  139.       ---------+--------------------------------------------+----------
  140.       fputc    : write a single character to a file     : ANSI
  141.       ---------+--------------------------------------------+----------
  142.       fputs    : write a string to a file            : ANSI
  143.       ---------+--------------------------------------------+----------
  144.       fread    : read from a file pointer            : ANSI
  145.       ---------+--------------------------------------------+----------
  146.       freopen  : reopen a file                : ANSI
  147.       ---------+--------------------------------------------+----------
  148.       fscanf   : formatted input from a file        : ANSI
  149.       ---------+--------------------------------------------+----------
  150.       fseek    : seek within a file             : ANSI
  151.       ---------+--------------------------------------------+----------
  152.       fsetpos  : set position within a file         : ANSI
  153.       ---------+--------------------------------------------+----------
  154.       fstat    : stat of a file                : UNIX
  155.       ---------+--------------------------------------------+----------
  156.       ftell    : get file position                : ANSI
  157.       ---------+--------------------------------------------+----------
  158.       fwrite   : write data to a file            : ANSI
  159.       ---------+--------------------------------------------+----------
  160.       getc       : get a single character from a file     : ANSI
  161.       ---------+--------------------------------------------+----------
  162.       getchar  : get a character from stdin         : ANSI
  163.       ---------+--------------------------------------------+----------
  164.       getcwd   : get current working directory        : UNIX
  165.       ---------+--------------------------------------------+----------
  166.       getfnl   : get file name list             : DICE
  167.       ---------+--------------------------------------------+----------
  168.       gets       : get a line from stdin            : ANSI
  169.       ---------+--------------------------------------------+----------
  170.       ioctl    : execute ioctl on file descriptor        : UNIX
  171.       ---------+--------------------------------------------+----------
  172.       isatty   : is a file descriptor a TTY         : UNIX
  173.       ---------+--------------------------------------------+----------
  174.       lseek    : seek in a file                : UNIX
  175.       ---------+--------------------------------------------+----------
  176.       mkdir    : create a directory             : UNIX
  177.       ---------+--------------------------------------------+----------
  178.       open       : open a file                : UNIX
  179.       ---------+--------------------------------------------+----------
  180.       perror   : print error message            : ANSI
  181.       ---------+--------------------------------------------+----------
  182.       printf   : formatted printing to standard out     : ANSI
  183.       ---------+--------------------------------------------+----------
  184.       putc       : write a single character to a file     : ANSI
  185.       ---------+--------------------------------------------+----------
  186.       putchar  : output character to stdout         : ANSI
  187.       ---------+--------------------------------------------+----------
  188.       puts       : write a string to a file            : ANSI
  189.       ---------+--------------------------------------------+----------
  190.       read       : read data from a file            : UNIX
  191.       ---------+--------------------------------------------+----------
  192.       remove   : delete a file                : ANSI
  193.       ---------+--------------------------------------------+----------
  194.       rename   : rename a file                : ANSI
  195.       ---------+--------------------------------------------+----------
  196.       rewind   : seek to file beginning            : ANSI
  197.       ---------+--------------------------------------------+----------
  198.       rmdir    : delete a directory             : UNIX
  199.       ---------+--------------------------------------------+----------
  200.       scanf    : formatted input from input         : ANSI
  201.       ---------+--------------------------------------------+----------
  202.       setvbuf  : change file buffering            : ANSI
  203.       ---------+--------------------------------------------+----------
  204.       sprintf  : formatted printing to a string        : ANSI
  205.       ---------+--------------------------------------------+----------
  206.       sscanf   : formatted input from a string        : ANSI
  207.       ---------+--------------------------------------------+----------
  208.       stat       : stat a file by name            : UNIX
  209.       ---------+--------------------------------------------+----------
  210.       tmpfile  : create a temporary file            : ANSI
  211.       ---------+--------------------------------------------+----------
  212.       tmpnam   : create a unique temporary file name    : ANSI
  213.       ---------+--------------------------------------------+----------
  214.       ungetc   : push character back to input stream    : ANSI
  215.       ---------+--------------------------------------------+----------
  216.       unlink   : delete a file                : UNIX
  217.       ---------+--------------------------------------------+----------
  218.       write    : write to a file                : UNIX
  219.       ---------+--------------------------------------------+----------
  220.  
  221. dice/MathFunctions                                         dice/MathFunctions
  222.  
  223.     Math Functions
  224.     --------------
  225.          Name    : Description                : Class
  226.          =======+===================================+=======
  227.          abs    : take absolute value of an int     : ANSI
  228.          -------+-----------------------------------+-------
  229.          acos    : take arc cosine            : ANSI
  230.          -------+-----------------------------------+-------
  231.          asin    : take arc sine of a double        : ANSI
  232.          -------+-----------------------------------+-------
  233.          atan    : take arc tangent of a double        : ANSI
  234.          -------+-----------------------------------+-------
  235.          cos    : take cosine of a double        : ANSI
  236.          -------+-----------------------------------+-------
  237.          _divs    : signed long divide            : DICE
  238.          -------+-----------------------------------+-------
  239.          _divu    : unsigned long divide            : DICE
  240.          -------+-----------------------------------+-------
  241.          exp    : return e to the exponent        : ANSI
  242.          -------+-----------------------------------+-------
  243.          fabs    : take absolute value            : ANSI
  244.          -------+-----------------------------------+-------
  245.          facos    : take floating point arc cosine    : UNIX
  246.          -------+-----------------------------------+-------
  247.          fasin    : take floating point arc sine        : UNIX
  248.          -------+-----------------------------------+-------
  249.          fatan    : take floating point arc tangent   : UNIX
  250.          -------+-----------------------------------+-------
  251.          fcos    : take floating point cosine        : UNIX
  252.          -------+-----------------------------------+-------
  253.          fexp    : floating point exponent        : UNIX
  254.          -------+-----------------------------------+-------
  255.          ffabs    : return absolute value of float    : UNIX
  256.          -------+-----------------------------------+-------
  257.          flog    : take log of a float            : UNIX
  258.          -------+-----------------------------------+-------
  259.          flog10 : take log of a float (base 10)     : UNIX
  260.          -------+-----------------------------------+-------
  261.          fpow    : return float to power of another  : UNIX
  262.          -------+-----------------------------------+-------
  263.          fsin    : return sine of a float        : UNIX
  264.          -------+-----------------------------------+-------
  265.          fsqrt    : return square root of a float     : UNIX
  266.          -------+-----------------------------------+-------
  267.          ftan    : return tan of a float         : UNIX
  268.          -------+-----------------------------------+-------
  269.          labs    : take absolute value of a long     : ANSI
  270.          -------+-----------------------------------+-------
  271.          log    : take log of a double            : ANSI
  272.          -------+-----------------------------------+-------
  273.          log10    : take log of a double (base 10)    : ANSI
  274.          -------+-----------------------------------+-------
  275.          _mods    : signed long modulus            : DICE
  276.          -------+-----------------------------------+-------
  277.          _modu    : unsigned long modulus         : DICE
  278.          -------+-----------------------------------+-------
  279.          _muls    : unsigned long multiply        : DICE
  280.          -------+-----------------------------------+-------
  281.          _mulu    : unsigned long multiply        : DICE
  282.          -------+-----------------------------------+-------
  283.          pow    : return number to power of another : ANSI
  284.          -------+-----------------------------------+-------
  285.          rand    : generate random number        : ANSI
  286.          -------+-----------------------------------+-------
  287.          sin    : return sine of a double        : ANSI
  288.          -------+-----------------------------------+-------
  289.          sqrt    : return square root of a double    : ANSI
  290.          -------+-----------------------------------+-------
  291.          srand    : set seed for random number        : ANSI
  292.          -------+-----------------------------------+-------
  293.          tan    : return tangent of a double        : ANSI
  294.          -------+-----------------------------------+-------
  295. dice/MiscFunctions,Miscellaneous                           dice/MiscFunctions
  296.  
  297.     Miscellaneous Functions
  298.     -----------------------
  299.     Name             : Description              : Class
  300.     =========================+================================+==========
  301.     abort             : abort a program          : ANSI
  302.     -------------------------+--------------------------------+----------
  303.     asctime          : convert time into text      : ANSI
  304.     -------------------------+--------------------------------+----------
  305.     assert             : assert that an expression is   : ANSI
  306.                  : true               :
  307.     -------------------------+--------------------------------+----------
  308.     atexit             : specify routine to call on      : ANSI
  309.                  : exit               :
  310.     -------------------------+--------------------------------+----------
  311.     chkabort         : check for ^C           : AmigaDOS
  312.     -------------------------+--------------------------------+----------
  313.     clock             : return system clock time      : ANSI
  314.     -------------------------+--------------------------------+----------
  315.     CreateDiceRexxPort     : create an application ARexx      : DICE
  316.                  : port               :
  317.     -------------------------+--------------------------------+----------
  318.     CreateGlobalDiceRexxPort : create a global ARexx port      : DICE
  319.     -------------------------+--------------------------------+----------
  320.     ctime             : convert time into text      : ANSI
  321.     -------------------------+--------------------------------+----------
  322.     DeleteDiceRexxPort     : delete a DICE ARexx port      : DICE
  323.     -------------------------+--------------------------------+----------
  324.     DoRexxCommand         : Parse an incomming ARexx      : DICE
  325.                  : command              :
  326.     -------------------------+--------------------------------+----------
  327.     exit             : exit from a program          : ANSI
  328.     -------------------------+--------------------------------+----------
  329.     _exit             : exit from a program          : DICE
  330.     -------------------------+--------------------------------+----------
  331.     expand_args         : expand command line (very      : DICE
  332.                  : useful!)              :
  333.     -------------------------+--------------------------------+----------
  334.     getenv             : get environment variable      : ANSI
  335.     -------------------------+--------------------------------+----------
  336.     GetDiceRexxPortSlot     : Determine an application ARexx : DICE
  337.                  : slot               :
  338.     -------------------------+--------------------------------+----------
  339.     GetHead          : get first element in EXEC list : DICE
  340.     -------------------------+--------------------------------+----------
  341.     GetPred          : get preceding element in EXEC  : DICE
  342.                  : list               :
  343.     -------------------------+--------------------------------+----------
  344.     GetSucc          : get succeeding element in EXEC : DICE
  345.                  : list               :
  346.     -------------------------+--------------------------------+----------
  347.     GetTail          : get last element in EXEC list  : DICE
  348.     -------------------------+--------------------------------+----------
  349.     localtime         : unpack time              : ANSI
  350.     -------------------------+--------------------------------+----------
  351.     LockAddr         : semaphore routine          : DICE
  352.     -------------------------+--------------------------------+----------
  353.     LockAddrB         : semaphore routine          : DICE
  354.     -------------------------+--------------------------------+----------
  355.     longjmp          : jump to a saved setjmp      : ANSI
  356.     -------------------------+--------------------------------+----------
  357.     main             : main program entry point      : ANSI
  358.     -------------------------+--------------------------------+----------
  359.     _main             : main program entry point      : DICE
  360.     -------------------------+--------------------------------+----------
  361.     onbreak          : Set ^C function          : DICE
  362.     -------------------------+--------------------------------+----------
  363.     PlaceRexxCommand     : Send a command to ARexx      : DICE
  364.     -------------------------+--------------------------------+----------
  365.     PlaceRexxCommandDirect     : send an ARexx command to an      : DICE
  366.                  : application              :
  367.     -------------------------+--------------------------------+----------
  368.     ProcessRexxCommands     : Handle incomming ARexx      : DICE
  369.                  : commands              :
  370.     -------------------------+--------------------------------+----------
  371.     qsort             : sort an array          : ANSI
  372.     -------------------------+--------------------------------+----------
  373.     raise             : raise a signal          : ANSI
  374.     -------------------------+--------------------------------+----------
  375.     rega4             : return contents of register A4 : DICE
  376.                  : (different from geta4!)      :
  377.     -------------------------+--------------------------------+----------
  378.     setbuf             : select alternative stream      : ANSI
  379.                  : buffering              :
  380.     -------------------------+--------------------------------+----------
  381.     setjmp             : prepare for future long jmp      : ANSI
  382.     -------------------------+--------------------------------+----------
  383.     signal             : establish event traps      : ANSI
  384.     -------------------------+--------------------------------+----------
  385.     sleep             : sleep for a while          : UNIX
  386.     -------------------------+--------------------------------+----------
  387.     stack_abort         : exit point for stack alloc      : DICE
  388.                  : failure              :
  389.     -------------------------+--------------------------------+----------
  390.     system             : call system command shell      : ANSI
  391.     -------------------------+--------------------------------+----------
  392.     time             : get current time          : ANSI
  393.     -------------------------+--------------------------------+----------
  394.     TryLockAddr         : semaphore routine          : DICE
  395.     -------------------------+--------------------------------+----------
  396.     TryLockAddrB         : semaphore routine          : DICE
  397.     -------------------------+--------------------------------+----------
  398.     UnLockAddr         : semaphore routine          : DICE
  399.     -------------------------+--------------------------------+----------
  400.     UnLockAddrB         : semaphore routine          : DICE
  401.     -------------------------+--------------------------------+----------
  402.     wbmain             : main program entry for      : AmigaDos
  403.                  : WorkBench              :
  404.     -------------------------+--------------------------------+----------
  405.  
  406. dice/MemoryFunctions                                       dice/MemoryFunctions
  407.     Memory Functions
  408.     ----------------
  409.         Name    : Description             : Class
  410.         ========+================================+==========
  411.         alloca    : allocate memory from the stack : UNIX
  412.         --------+--------------------------------+----------
  413.         bcmp    : compare two memory buffers     : UNIX
  414.         --------+--------------------------------+----------
  415.         bcopy    : copy memory             : UNIX
  416.         --------+--------------------------------+----------
  417.         bzero    : zero memory             : UNIX
  418.         --------+--------------------------------+----------
  419.         calloc    : allocate memory         : ANSI
  420.         --------+--------------------------------+----------
  421.         clrmem    : zero memory             : AmigaDOS
  422.         --------+--------------------------------+----------
  423.         cmpmem    : compare two memory buffers     : UNIX
  424.         --------+--------------------------------+----------
  425.         free    : free allocated memory      : ANSI
  426.         --------+--------------------------------+----------
  427.         malloc    : allocate memory         : ANSI
  428.         --------+--------------------------------+----------
  429.         memcmp    : compare two memory buffers     : ANSI
  430.         --------+--------------------------------+----------
  431.         memcpy    : copy memory             : ANSI
  432.         --------+--------------------------------+----------
  433.         memmove : move memory             : ANSI
  434.         --------+--------------------------------+----------
  435.         memset    : set memory to value         : ANSI
  436.         --------+--------------------------------+----------
  437.         movmem    : move memory             : UNIX
  438.         --------+--------------------------------+----------
  439.         realloc : reallocate memory         : ANSI
  440.         --------+--------------------------------+----------
  441.         setmem    : set memory to value         : UNIX
  442.         --------+--------------------------------+----------
  443.  
  444. dice/AslBase,DiceCacheBase,DiskfontBase,DOSBase,FifoBase,GadToolsBase,IconBase,IntuitionBase,LayersBase,MathBase,MathIeeeDoubBasBase,MathIeeeDoubTransBase,MathIeeeSingBasBase,MathIeeeSingTransBase,MathTransBase,RexxSysBase,SysBase,TimerBase,TranslatorB
  445. se,UtilityBase
  446.  
  447.     AslBase, DiceCacheBase, DiskfontBase, DOSBase, FifoBase,
  448.     GadToolsBase, IconBase, IntuitionBase, LayersBase, MathBase,
  449.     MathIeeeDoubBasBase, MathIeeeDoubTransBase, MathIeeeSingBasBase,
  450.     MathIeeeSingTransBase, MathTransBase, RexxSysBase, SysBase,
  451.     TimerBase, TranslatorBase, UtilityBase
  452.  
  453.     FUNCTION
  454.     DICE will automatically open libraries for you (DICE)
  455.  
  456.     DESCRIPTION
  457.     With DICE you need not worry about opening or closing Amiga
  458.     libraries.  You don't have to deal with the mess and hassle of
  459.     checking error returns from each open.    If a function call to a
  460.     library is used, the library base variable will be referenced.    If
  461.     you did not explicitly define the variable, DICE will insert it,
  462.     along with code to open and close the library.
  463.  
  464.     For example, if the _IntuitionBase base variable is referenced (say,
  465.     with extern) but not declared then _IntuitionBase will be
  466.     automatically declared in auto.lib.  Additionally, auto.lib adds
  467.     routines to the autoinit and autoexit sequences that automatically
  468.     open "intuition.library" before _main and close it after _exit. If
  469.     the auto-open fails the program will be aborted before _main is ever
  470.     called. The autoexit routine that closes the library first checks to
  471.     see if the base variable is NULL and skips trying to close the
  472.     library if so.
  473.  
  474.     EXAMPLE
  475.     /*
  476.     **  Example program which just calls an
  477.     **  intuition.library function without
  478.     **  bothering to open the library.
  479.     */
  480.     main()
  481.     {
  482.        DisplayBeep( 0 );
  483.     }
  484.  
  485. dice/abort                                                        dice/abort
  486.  
  487.     FUNCTION
  488.     abort a program with an error (ANSI)
  489.  
  490.     SYNTAX
  491.     #include <stdlib.h>
  492.     void abort(void);
  493.  
  494.     DESCRIPTION
  495.     abort aborts a program with a non-zero exit code.  The default abort
  496.     routine in c.lib does the equivalent of an exit(20);. Programmers may
  497.     override the default abort routine with their own.
  498.  
  499.     RESULTS
  500.     abort never returns
  501.  
  502.     SEE ALSO
  503.     assert
  504.  
  505.     EXAMPLE
  506.     #include <stdio.h>
  507.     #include <stdlib.h>
  508.     main(int ac, char**av)
  509.     {
  510.        if (ac == 1) {
  511.           puts("Hey, I expected a parameter!");
  512.           abort();
  513.           }
  514.           puts("Thanks!");
  515.           return(0);
  516.     }
  517.  
  518. dice/abs,labs                                                  dice/abs,labs
  519.  
  520.     FUNCTION
  521.     take absolute value (ANSI)
  522.  
  523.     SYNTAX
  524.     #include <stdio.h>
  525.     #include <stdlib.h>
  526.     int r = [l]abs(n);
  527.     int n;
  528.  
  529.     DESCRIPTION
  530.     abs takes the absolute value of an int; labs takes the absolute value
  531.     of a long.  Both return the absolute value of the specified integer.
  532.     For example, r = n if n >= 0, r = -n (positive) if n < 0. Normally
  533.     one would not use this call due to overhead, but it exists for
  534.     compatibility.
  535.  
  536.     ## WARNING: The absolute value of 0x80000000 cannot be taken.
  537.     ## 0x80000000 will be returned.
  538.  
  539.     || NOTE: UNDER DICE, sizeof(int) == sizeof(long) and these two
  540.     || functions are thus identical.
  541.  
  542.     INPUTS
  543.     int n;            integer
  544.  
  545.     RESULTS
  546.     int r;            absolute value of integer
  547.  
  548.     EXAMPLE
  549.     #include<stdio.h>
  550.     #include <stdlib.h>
  551.     main()
  552.     {
  553.        int n = -53;
  554.        printf("The absolute value of %d is %d\n", n, abs(n));
  555.        sleep(1);
  556.        printf("But its faster if you write a macro:\n");
  557.        #define abs(x)  (((x) < 0) ? -(x) : (x))
  558.        sleep(1);
  559.        printf("The absolute value of %d is %d\n", n, abs(n));
  560.        return(0);
  561.     }
  562.  
  563. dice/access                                                      dice/access
  564.  
  565.     FUNCTION
  566.     determine whether file is accessible (UNIX)
  567.  
  568.     SYNTAX
  569.     #include <stdio.h>
  570.     int r = access(filename, mode);
  571.     const char *filename;
  572.     int mode;
  573.  
  574.     DESCRIPTION
  575.     access returns 0 upon success, -1 if access with the requested modes
  576.     was impossible.  The filename serves as a pointer to the string of
  577.     the filename we wish to check, and the modes are what we expect the
  578.     file to be able to do.    The modes may be one or more of the following
  579.     OR'd together.
  580.  
  581.      0   check for existence of file only
  582.      1   check execute permission for file
  583.      2   check write permission for file
  584.     4   check read permission for file
  585.  
  586.     INPUTS
  587.     char *filename;     file to check
  588.  
  589.     int mode;        modes as specified above
  590.  
  591.     RESULTS
  592.     int r;            0 if modes available, -1 if not
  593.  
  594.     SEE ALSO
  595.     open, fopen
  596.  
  597.     EXAMPLE
  598.     #include <stdio.h>
  599.  
  600.     main(int ac, char **av)
  601.     {
  602.        char *name;
  603.        if (ac == 1)
  604.        {
  605.           puts("Expected a file name argument");
  606.           exit(1);
  607.        }
  608.        name = av[1];
  609.        if (access(name, 0) == 0) {
  610.          puts("It exists");
  611.           if (access(name, 1) == 0)
  612.          puts("It is executable");
  613.           if (access(name, 2) == 0)
  614.             puts("I can write to it!");
  615.           if (access(name, 4) == 0)
  616.             puts("I can even read from it!");
  617.        }
  618.        else
  619.          puts("Hmmm, that file does not exist");
  620.     }
  621.  
  622. dice/acos                                                          dice/acos
  623.  
  624.     FUNCTION
  625.     take arc cosine (ANSI)
  626.  
  627.     LIBRARY
  628.     m.lib
  629.  
  630.     SYNTAX
  631.     #include <math.h>
  632.     double a = acos(b);
  633.     double b;
  634.  
  635.     DESCRIPTION
  636.     acos returns the arc cosine of a double quantity.
  637.  
  638.     INPUTS
  639.     double b;        double floating point value
  640.  
  641.     RESULTS
  642.     double a;        result double floating point value
  643.  
  644.     SEE ALSO
  645.     asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan, facos,
  646.     fasin
  647.  
  648.     EXAMPLE
  649.     /*
  650.      *  compile with the math library -lm
  651.      */
  652.     #include <math.h>
  653.     #include <stdio.h>
  654.     main()
  655.     {
  656.        {
  657.           double a = acos(0.25);
  658.           printf("acos 0.25 = %lf\n", a); /* 1.318   */
  659.        }
  660.        {  /* less accuracy     */
  661.           float a = facos(0.25);
  662.           printf("acos 0.25 = %lf\n", (double)a);
  663.        }
  664.        return(0);
  665.     }
  666.  
  667. dice/alloca                                                      dice/alloca
  668.  
  669.     FUNCTION
  670.     allocate memory from the stack (UNIX)
  671.  
  672.     SYNTAX
  673.     #include <stdlib.h>
  674.     void *ptr = alloca(long bytes);
  675.  
  676.     DESCRIPTION
  677.     alloca comes from the UNIX world.  It allocates memory off the stack
  678.     for use within a procedure.  The allocated memory is automatically
  679.     freed when the subroutine returns.
  680.  
  681.     :: Beginner's Note: Do not use alloca if you can help it; alloca is
  682.     :: not easily portable across machines.
  683.  
  684.     || NOTE: When a low stack condition arises, alloca will abort by
  685.     || printing an error message and calling abort;  alloca does not
  686.     || currently try to allocate dynamic memory when it runs out of
  687.     || stack. Some implementations of alloca use alloca(0) to free
  688.     || allocated stack. This feature is not currently implemented in
  689.     || DICE's alloca call.
  690.  
  691.     SEE ALSO
  692.     setjmp, longjmp
  693.  
  694.     EXAMPLE
  695.     #include <alloca.h>
  696.     #include <stdio.h>
  697.     main(int ac, char*av[])
  698.     {
  699.        char *ptr;
  700.        if (ac == 1) {
  701.           puts("I need test string");
  702.           exit(1);
  703.        }
  704.        ptr = alloca(strlen(av[1]) + 8);
  705.        sprintf(ptr, "FOO.%s", av[1]);
  706.        puts(ptr);
  707.        return(0);
  708.     }
  709.  
  710. dice/asctime                                                    dice/asctime
  711.  
  712.     FUNCTION
  713.     convert broken down time into standard text (ANSI)
  714.  
  715.     SYNTAX
  716.     #include <time.h>
  717.     char *str = asctime(ts);
  718.     const struct tm *ts;
  719.  
  720.     DESCRIPTION
  721.     asctime converts a broken down time in the tm structure to an ASCII
  722.     string and returns a pointer to that string. The time string format
  723.     is:
  724.  
  725.     on Dec 8 01:53:33 1987\n\0
  726.  
  727.     where \n stands for a newline character and \0 is a terminating NULL.
  728.     The string is stored in a static buffer shared by both asctime and
  729.     ctime and so will be overwritten whenever either function is called.
  730.  
  731.     INPUTS
  732.     struct tm *ts;        pointer to a broken down time structure
  733.  
  734.     RESULTS
  735.     char *str;        pointer to static string
  736.  
  737.     SEE ALSO
  738.     time, localtime, asctime, strftime, ctime, clock
  739.  
  740.     EXAMPLE
  741.     #include <stdio.h>
  742.     #include <time.h>
  743.  
  744.     main()
  745.     {
  746.        time_t t = time(NULL);
  747.        fputs(asctime(localtime(&t)), stdout);
  748.        return(0);
  749.     }
  750.  
  751. dice/assert                                                      dice/assert
  752.  
  753.     FUNCTION
  754.     assert that an expression is true,  else abort (ANSI)
  755.  
  756.     SYNTAX
  757.     #include <assert.h>
  758.     assert(condition);   /* MACRO */
  759.  
  760.     DESCRIPTION
  761.     assert checks the condition and if not true prints an error message
  762.     indicating the source filename and line number that the assertion
  763.     failed at, and then aborts.  The DICE version of assert generates a
  764.     single static string in assert.h for each module containing the file
  765.     name. Multiple usages of assert refer to the same physical filename
  766.     string.
  767.  
  768.     INPUTS
  769.     expression;        an expression which the macro negates.
  770.  
  771.     SEE ALSO
  772.     abort
  773.  
  774.     EXAMPLE
  775.     #include <assert.h>
  776.  
  777.     main(int ac, char **av)
  778.     {
  779.        assert(ac > 1); /*  expect at least one argument! */
  780.        return(0);
  781.     }
  782.  
  783. dice/asin                                                          dice/asin
  784.  
  785.     FUNCTION
  786.     take the arc sine of a double quantity (ANSI)
  787.  
  788.     LIBRARY
  789.     m.lib
  790.  
  791.     SYNTAX
  792.     #include <math.h>
  793.     double a = asin(b);
  794.     double b;
  795.  
  796.     DESCRIPTION
  797.     asin takes the arc sine of a floating point quantity.
  798.  
  799.     INPUTS
  800.     double b;        double floating point value
  801.  
  802.     RESULTS
  803.     double a;        result double floating point value
  804.  
  805.     SEE ALSO
  806.     acos, cos, exp, fabs, log, log10, pow, sin, sqrt, tan facos, fasin
  807.  
  808.     EXAMPLE
  809.     /*
  810.     *  compile with the math library -lm
  811.     */
  812.     #include <math.h>
  813.     #include <stdio.h>
  814.     main()
  815.     {
  816.        {
  817.           double a = asin(0.25);
  818.           printf("asin 0.25 = %lf\n", a);  /* 0.2527 */
  819.        }
  820.        {  /* less accuracy    */
  821.           float a = fasin(0.25);
  822.           printf("asin 0.25 = %lf\n", (double)a);
  823.        }
  824.        return(0);
  825.     }
  826.  
  827. dice/atan                                                          dice/atan
  828.  
  829.     FUNCTION
  830.     take arc tan of a double quantity (ANSI)
  831.  
  832.     LIBRARY
  833.     m.lib
  834.  
  835.     SYNTAX
  836.     #include <math.h>
  837.     double a = atan(b);
  838.     double b;
  839.  
  840.     DESCRIPTION
  841.     atan takes the arc tangent of a floating point quantity.
  842.  
  843.     INPUTS
  844.     double b;        double floating point value
  845.  
  846.     RESULTS
  847.     double a;        result double floating point value
  848.  
  849.     SEE ALSO
  850.     acos, asin, cos, exp, fabs, log, log10, pow, sin, sqrt, tan facos,
  851.     fasin
  852.  
  853.     EXAMPLE
  854.     /*
  855.      *  compile with the math library -lm
  856.      */
  857.     #include <math.h>
  858.     #include <stdio.h>
  859.  
  860.     main()
  861.     {
  862.        {
  863.           double a = atan(0.25);
  864.           printf("atan 0.25 = %lf\n", a);  /* 0.245   */
  865.        }
  866.        {  /*  less accuracy   */
  867.           float a = fatan(0.25);
  868.           printf("atan 0.25 = %lf\n", (double)a);
  869.        }
  870.        return(0);
  871.     }
  872.  
  873. dice/atexit                                                      dice/atexit
  874.  
  875.     FUNCTION
  876.     specify routine that is automatically called on exit (ANSI)
  877.  
  878.     SYNTAX
  879.     #include <stdio.h>
  880.     #include <stdlib.h>
  881.     int error = atexit(funcptr);
  882.     void (*fptr)(void);
  883.  
  884.     DESCRIPTION
  885.     The atexit routine adds a function to the list of functions called
  886.     when the program exits.  The atexit routine is called before stdio
  887.     and file descriptors are closed down.  This exit function is called
  888.     whenever the program exits, even if main returns normally. atexit
  889.     will return 0 on success, -1 on failure. Some systems limit the
  890.     number of atexit functions one can add (DICE does not) so if you add
  891.     more than one you should check the return value.
  892.  
  893.     INPUTS
  894.     void (*fptr)(void);
  895.                 routine to add to exit call list, takes no
  896.                 arguments and returns nothing.
  897.  
  898.     RESULTS
  899.     int error;        0 on success, -1 on failure.
  900.  
  901.     SEE ALSO
  902.     onbreak
  903.  
  904.     EXAMPLE
  905.     /*
  906.      *  Atexit is useful to free up resources that would
  907.      *  otherwise not be freed up by DICE. For example, any
  908.      *  thing AllocMem'd.  The atexit function is called on
  909.      *  any exit ... return from main, call to exit, or ^C.
  910.      *
  911.      *  Normally your atexit routine cannot make assumptions
  912.      *  as to what has been allocated and what has not since
  913.      *  exit can be called from anywhere in the program.
  914.      */
  915.     #include <stdio.h>
  916.     #include <stdlib.h>
  917.     extern void *AllocMem();
  918.     void *MemPtr; long MemLen;
  919.  
  920.     void myexit(void)
  921.     {
  922.        if (MemPtr) /*  only if it is allocated */
  923.            FreeMem(MemPtr, MemLen);
  924.        MemPtr = NULL;
  925.     }
  926.  
  927.     /*  Now we can take a ^C anywhere... before we allocate,
  928.      *  after, or even after we free (note I am careful to set
  929.      *  MemPtr back to NULL!)
  930.      */
  931.     main()
  932.     {
  933.        short i;
  934.        atexit(myexit);
  935.  
  936.        for (i = 0; i < 50; ++i)
  937.           printf("Before %d\t(%ld)\n", i, AvailMem(0) );
  938.        MemLen = 32;
  939.        MemPtr = AllocMem(MemLen, 0);
  940.        if (! MemPtr) {
  941.           exit(20);
  942.        }
  943.  
  944.        for (i = 0; i < 50; ++i)
  945.           printf("During %d\t(%ld)\n", i, AvailMem(0) );
  946.  
  947.        FreeMem(MemPtr, MemLen);
  948.        MemPtr = NULL; /* Mark as freed */
  949.  
  950.        for (i = 0; i < 50; ++i)
  951.           printf("After  %d\t(%ld)\n", i, AvailMem(0) );
  952.        return(0);
  953.     }
  954.  
  955. dice/atof                                                          dice/atof
  956.  
  957.     FUNCTION
  958.     convert string into double floating point value (ANSI)
  959.  
  960.     SYNTAX
  961.     #include <stdio.h>
  962.     #include <stdlib.h>
  963.     double d = atof(str);
  964.     const char *str;
  965.  
  966.     DESCRIPTION
  967.     atof converts a string into a double floating point value; it is
  968.     equivalent to calling strtod(str, NULL).  Please refer to strtod for
  969.     more information.
  970.  
  971.     INPUTS
  972.     char *str;        string, like "1.234E-4";
  973.  
  974.     RESULTS
  975.     double d;        double fp representation of string
  976.  
  977.     SEE ALSO
  978.     strtod
  979.  
  980. dice/atoi,atol                                                dice/atoi,atol
  981.  
  982.     FUNCTION
  983.     convert string into integer (ANSI)
  984.  
  985.     SYNTAX
  986.     #include <stdio.h>
  987.     #include <stdlib.h>
  988.     int x =atoi(str);
  989.     long y = atol(str);
  990.     const char *str;
  991.  
  992.     DESCRIPTION
  993.     atoi and atol convert a string of decimal integers into an integer.
  994.     It skips initial white space, processes an optional negative sign
  995.     ('-'), processes digits '0' - '9', and returns the integer. atoi and
  996.     atol have been superseded by the strtol function which can handle
  997.     numbers of any base.
  998.  
  999.     || NOTE: Under DICE, sizeof(int) == sizeof(long), and thus atoi and
  1000.     || atol are exactly the same.
  1001.  
  1002.     INPUTS
  1003.     char *str;        string to convert to int
  1004.  
  1005.     RESULTS
  1006.     int x;            integer result long y; integer result
  1007.  
  1008.     SEE ALSO
  1009.     strtol
  1010.  
  1011.     EXAMPLE
  1012.     #include <stdio.h>
  1013.     #include <stdlib.h>
  1014.     main()
  1015.     {
  1016.        int i = atoi("  \t\t -123");
  1017.        printf("i = %d (-123?)\n", i);
  1018.        return(0);
  1019.     }
  1020.  
  1021. dice/bcmp                                                          dice/bcmp
  1022.  
  1023.     FUNCTION
  1024.     compare two memory buffers (UNIX)
  1025.  
  1026.     SYNTAX
  1027.     #include <string.h>
  1028.     int r = bcmp(s1, s2, bytes)
  1029.     void *s1;
  1030.     void *s2;
  1031.     size_t bytes;
  1032.  
  1033.     DESCRIPTION
  1034.     bcmp compares two memory buffers.  A byte by byte (unsigned)
  1035.     comparison is done.  When a comparison fails and the byte in s1 is
  1036.     less than the byte in s2 then -1 is returned.  If the byte in s1 is
  1037.     greater than the byte in s2 then 1 is returned.  If the count is
  1038.     exhausted and all comparisons succeed then 0 is returned indicating
  1039.     the two buffers are the same.
  1040.  
  1041.     INPUTS
  1042.     void *s1;        pointer to first buffer
  1043.  
  1044.     void *s2;        pointer to second buffer
  1045.  
  1046.     size_t bytes;        size of each buffer
  1047.  
  1048.     RESULTS
  1049.     int r;            -1 if buf s1 < buf s2, 0 if buf s1 == buf s2, 1
  1050.                 if buf s1 > buf s2.
  1051.  
  1052.     SEE ALSO
  1053.     cmpmem, memcmp, strcmp
  1054.  
  1055.     EXAMPLE
  1056.     #include <stdlib.h>
  1057.     #include <assert.h>
  1058.     main()
  1059.     {
  1060.        unsigned char buf1[] = {5, 12, 13};
  1061.        unsigned char buf2[] = {5, 12, 13};
  1062.        int r;
  1063.        r = bcmp(buf1, buf2, 3);
  1064.        assert(r == 0);
  1065.  
  1066.        buf1[2] = 12;
  1067.        r = bcmp(buf1, buf2, 3);
  1068.        assert(r < 0);
  1069.  
  1070.        buf1[2] = 200;
  1071.        r = bcmp(buf1, buf2, 3);
  1072.        assert(r > 0);
  1073.        return(0);
  1074.     }
  1075.  
  1076. dice/c.o                                                            dice/c.o
  1077.  
  1078.     FUNCTION
  1079.     DICE startup module for all C programs
  1080.  
  1081.     SYNTAX
  1082.     The module dlib:c.o is normally specified first in a link line, or
  1083.     automatically by dcc.
  1084.  
  1085.     DESCRIPTION
  1086.     C programs require a bit of code (called "glue") in order to start
  1087.     execution.  This code saves machine registers, sets up global
  1088.     storage, parses arguments, open libraries and, after the program
  1089.     terminates, communicates results back to the host Operating System.
  1090.     For use with the Amiga, DICE includes a suitable startup module
  1091.     called c.o.  This module is automatically include by dcc, and need
  1092.     not concern most programmers.
  1093.  
  1094.     The startup module performs the following tasks:
  1095.  
  1096.     1) Save non-scratch registers.
  1097.  
  1098.     2) If resident, allocate space for both DATA (Initialized globals) &
  1099.        BSS (Uninitialized globals - set to zero).  Copy initialized data
  1100.        into the allocated space. Clear the BSS portion of the data space.
  1101.        If the BSS has already been allocated by the load module but not
  1102.        cleared, clear the BSS portion of the data space.
  1103.  
  1104.     3) Clear the ^C (Control C) signal
  1105.  
  1106.     4) Setup _SysBase, the pointer to the Amiga's master library, Exec.
  1107.  
  1108.     5) Call all AUTOINIT subroutines (this usually results in at least
  1109.        the dos.library being opened).
  1110.  
  1111.     6) Call _main (usually the c.lib version, but you may override it).
  1112.  
  1113.     7) Fall through to _exit(0).  Note that while c.a falls through to
  1114.        _exit after calling _main, _main itself calls main with:
  1115.        exit(main(args...)); Thus, main() is always expected to return a
  1116.        valid value (i.e. not void).
  1117.  
  1118.     C.O. also handles the low-level _exit (__exit:) in the following
  1119.     sequence:
  1120.  
  1121.     1) Call all AUTOEXEC subroutines (this normally closes the DOS
  1122.        library and other automatically opened libraries such as floating
  1123.        point).
  1124.  
  1125.     2) Free all memory allocated by the task, including the small data
  1126.        segment & BSS space.  Note that all variables we use hereafter
  1127.        have already been placed in registers since the dataspace is no
  1128.        longer valid.
  1129.  
  1130.     3) If started from workbench, reply to the workbench message, _WBMsg.
  1131.  
  1132.     4) Restore original registers and rts (exit back to the Operating
  1133.        System).
  1134.  
  1135.     c.o also exists in c.lib, however that version is not normally used.
  1136.  
  1137.     || NOTE: Normally the programmer does not override the startup object
  1138.     || file (c.o).
  1139.  
  1140.     However, in some cases a programmer will want to override _main, as
  1141.     in:
  1142.  
  1143.         _main(len, arg) int len; char *arg; {... }
  1144.  
  1145.     The _main entry point is passed the length and arg pointer unmodified
  1146.     from the OS. When you override _main you cannot call any stdio
  1147.     (fopen, fclose, puts, printf, etc...), any low level IO (open, close,
  1148.     read, write, etc...), or any C memory allocation routine (malloc,
  1149.     etc...).
  1150.  
  1151.     Normally _main will be overridden if the programmer wishes to save
  1152.     space, and makes only Amiga system calls (such as Open, Close, Read,
  1153.     Write, FindTask, etc.). Overriding the C.LIB generally makes
  1154.     executables much smaller because no extraneous stdio or low level IO
  1155.     routines are brought in from c.lib. Normally you exit out of _main by
  1156.     calling _exit(code) (note the underscore).
  1157.  
  1158. dice/calloc                                                      dice/calloc
  1159.  
  1160.     FUNCTION
  1161.     allocate memory and clear (ANSI)
  1162.  
  1163.     SYNTAX
  1164.     #include <stdlib.h>
  1165.     void *ptr = calloc(objsize, numobjs)
  1166.     size_t objsize;
  1167.     size_t numobjs;
  1168.  
  1169.     DESCRIPTION
  1170.     Numobjs objects each objsize in size are allocated contiguously and a
  1171.     pointer to the first object is returned.  The memory is cleared to 0.
  1172.     Effectively this is equivalent to malloc(objsize * numobjs), and then
  1173.     setmem(ptr, objsize * numobjs, 0) . calloc returns NULL if the memory
  1174.     cannot be allocated.
  1175.  
  1176.     INPUTS
  1177.     size_t objsize;     size of each object
  1178.  
  1179.     size_t numobjs;     number of objects to allocate
  1180.  
  1181.     RESULTS
  1182.     void *ptr;        pointer to first object
  1183.  
  1184.     SEE ALSO
  1185.     malloc, strdup
  1186.  
  1187.     EXAMPLE
  1188.     /*
  1189.      *  allocate 16 objects and fill with junk
  1190.      */
  1191.     #include <stdlib.h>
  1192.     #include <assert.h>
  1193.     typedef struct
  1194.     {
  1195.        long a, b, c;
  1196.     }
  1197.     Junk;
  1198.     main()
  1199.     {
  1200.        Junk *jp;
  1201.        jp = calloc(sizeof(Junk), 16);
  1202.        assert(jp);
  1203.        {
  1204.           Junk *tj = jp;
  1205.           short i;
  1206.           for (i = 0; i < 16; ++i, ++tj)
  1207.           {
  1208.          tj->a = 1;
  1209.          tj->b = 2;
  1210.          tj->c = 3;
  1211.           }
  1212.        }
  1213.     free(jp);
  1214.     return(0);
  1215.     }
  1216.  
  1217. dice/chdir                                                        dice/chdir
  1218.  
  1219.     FUNCTION
  1220.     change current directory (UNIX)
  1221.  
  1222.     SYNTAX
  1223.     #include <stdio.h>
  1224.     int r = chdir(path);
  1225.     const char *path;
  1226.  
  1227.     DESCRIPTION
  1228.     chdir changes the current directory to the specified path, returning
  1229.     0 on success and -1 on failure.
  1230.  
  1231.     || NOTE: When a program exits, the original directory will be
  1232.     || restored.
  1233.  
  1234.     INPUTS
  1235.     char *path;        path to chdir into
  1236.  
  1237.     RESULTS
  1238.     int r;            return value, 0 if ok, -1 if error
  1239.  
  1240.     SEE ALSO
  1241.     getcwd
  1242.  
  1243.     EXAMPLE
  1244.     #include <stdio.h>
  1245.     char buf[512];
  1246.     main(int ac, char **av)
  1247.     {
  1248.        getcwd(buf, sizeof(buf));
  1249.        if (chdir("RAM:")) {
  1250.           puts("Couldn't chdir into RAM:");
  1251.           exit(1);
  1252.        }
  1253.        FILE *fp;
  1254.        if (fp = fopen("yy", "w")) {
  1255.           fputs("Fight for vegetable rights!\n", fp);
  1256.           fclose(fp);
  1257.           puts("created file yy in RAM:");
  1258.        }
  1259.        if (chdir(buf)) {
  1260.           printf("Unable to chdir back into %s\n", buf);
  1261.        }
  1262.        return(0);
  1263.     }
  1264.  
  1265. dice/chkabort                                                  dice/chkabort
  1266.  
  1267.     FUNCTION
  1268.     Check for ^C and take the appropriate action (AmigaDOS)
  1269.  
  1270.     SYNTAX
  1271.     (void) chkabort(void);
  1272.  
  1273.     DESCRIPTION
  1274.     chkabort checks for a ^C and takes the appropriate action.  If the
  1275.     appropriate action is to exit then this routine does not return.
  1276.     Stdio and other routines will call chkabort at various points.    The
  1277.     action taken by ^C may be set by the signal or onbreak calls.
  1278.  
  1279.     SEE ALSO
  1280.     onbreak, atexit, signal
  1281.  
  1282.     EXAMPLE
  1283.     /*
  1284.      *  wait for somebody to hit ^C (note that this is very
  1285.      *  wasteful of CPU and thus isn't a real good example).
  1286.      */
  1287.     main()
  1288.     {
  1289.        int i;
  1290.        for (i = 0; i < 10000000; ++i)
  1291.           chkabort();
  1292.        return(0);
  1293.     }
  1294.  
  1295. dice/clearerr                                                  dice/clearerr
  1296.  
  1297.     FUNCTION
  1298.     Clear error associated with a file pointer (ANSI)
  1299.  
  1300.     SYNTAX
  1301.     #include <stdio.h>
  1302.     void clearerr(fp);
  1303.     (MACRO) FILE *fp;
  1304.  
  1305.     DESCRIPTION
  1306.     The clearerr macro clears both the EOF flag and the ERROR flag
  1307.     associated with a file pointer. When an ERROR occurs on a file
  1308.     pointer, addition fread, fwrite, etc. calls will not work until the
  1309.     ERROR indicator is cleared.
  1310.  
  1311.     || NOTE: Refer to the file_pointer manual page for general
  1312.     || information.
  1313.  
  1314.     INPUTS
  1315.     FILE *fp;        file pointer to clear the error on.
  1316.  
  1317.     RESULTS
  1318.     none;            the error and EOF indicators are cleared
  1319.  
  1320.     SEE ALSO
  1321.     feof, ferror, rewind, fseek
  1322.  
  1323. dice/clock                                                        dice/clock
  1324.  
  1325.     FUNCTION
  1326.     return system clock value (ANSI)
  1327.  
  1328.     SYNTAX
  1329.     #include <time.h>
  1330.     clock_t clk = clock(void);
  1331.  
  1332.     DESCRIPTION
  1333.     clock returns the system clock in ticks.  To obtain seconds from
  1334.     ticks divide the returned value by CLK_TCK in <time.h>.
  1335.  
  1336.     INPUTS
  1337.     none
  1338.  
  1339.     RESULTS
  1340.     clock_t clk;        system clock time value
  1341.  
  1342.     SEE ALSO
  1343.     time, localtime, asctime, strftime, ctime, clock
  1344.  
  1345.     EXAMPLE
  1346.     #include <stdio.h>
  1347.     #include <time.h>
  1348.  
  1349.     main()
  1350.     {
  1351.        clock_t clk = clock();
  1352.        long i;
  1353.        clk = clk + CLK_TCK;
  1354.        for (i = 0; clk - clock() > 0; ++i)
  1355.           ;
  1356.        printf("The FOR loop calling clock() took\
  1357.            %d loops in one second\n", i);
  1358.        return(0);
  1359.     }
  1360.  
  1361. dice/close                                                        dice/close
  1362.  
  1363.     FUNCTION
  1364.     close a file descriptor (UNIX)
  1365.  
  1366.     SYNTAX
  1367.     #include <fcntl.h>
  1368.     int r = close(fd);
  1369.     int fd;
  1370.  
  1371.     DESCRIPTION
  1372.     close closes a file descriptor.  If an error occurs or the descriptor
  1373.     is invalid, a non-zero return code will result and errno will be set
  1374.     to the appropriate error condition.
  1375.  
  1376.     || NOTE: Refer to the file_descriptor manual page for general
  1377.     || information.  Unlike file pointers and file handles, the file
  1378.     || descriptor is checked for validity and if illegal, an error will
  1379.     || be returned.
  1380.  
  1381.     INPUTS
  1382.     int fd;         file descriptor to close, the file descriptor
  1383.                 becomes invalid after this call
  1384.  
  1385.     RESULTS
  1386.     int r;            return value, 0 == ok, non-zero == error
  1387.  
  1388.     SEE ALSO
  1389.     creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read, rmdir,
  1390.     unlink, write
  1391.  
  1392.     See open for an example
  1393.  
  1394. dice/cmpmem                                                      dice/cmpmem
  1395.  
  1396.     FUNCTION
  1397.     compare two memory buffers (UNIX)
  1398.  
  1399.     SYNTAX
  1400.     #include <string.h>
  1401.     int r = cmpmem(s1, s2, bytes)
  1402.     void *s1;
  1403.     void *s2;
  1404.     size_t bytes;
  1405.  
  1406.     DESCRIPTION
  1407.     Like bcmp, this function compares two memory buffers.  A byte by byte
  1408.     (unsigned) comparison is done.    When a comparison fails and the byte
  1409.     in s1 is less than the byte in s2 then -1 is returned. If the byte in
  1410.     s1 is greater than the byte in s2 then 1 is returned. If the count is
  1411.     exhausted and all comparisons succeed then 0 is returned indicating
  1412.     the two buffers are the same.
  1413.  
  1414.     INPUTS
  1415.     void *s1;        pointer to first buffer
  1416.  
  1417.     void *s2;        pointer to second buffer
  1418.  
  1419.     size_t bytes;        size of each buffer
  1420.  
  1421.     RESULTS
  1422.     int r;            -1 if buf s1 < buf s2, 0 if buf s1 == buf s2, 1
  1423.                 if buf s1 > buf s2.
  1424.  
  1425.     SEE ALSO
  1426.     bcmp, memcmp
  1427.  
  1428.     EXAMPLE
  1429.     #include <stdlib.h>
  1430.     #include <assert.h>
  1431.     main()
  1432.     {
  1433.        unsigned char buf1[] = {3, 5, 7, 11, 13};
  1434.        unsigned char buf2[] = {3, 5, 7, 11, 13};
  1435.        int r;
  1436.  
  1437.        r = cmpmem(buf1, buf2, 5);
  1438.        assert(r == 0);
  1439.        buf1[2] = 2;
  1440.        r = cmpmem(buf1, buf2, 5);
  1441.        assert(r < 0);
  1442.        buf1[2] = 200;
  1443.        r = cmpmem(buf1, buf2, 5);
  1444.        assert(r > 0);
  1445.        return(0);
  1446.     }
  1447.  
  1448. dice/cos,fcos                                                  dice/cos,fcos
  1449.  
  1450.     FUNCTION
  1451.     cos: return cosine of a double (ANSI)
  1452.     fcos: return cosine of a float (ANSI)
  1453.  
  1454.     LIBRARY
  1455.     m.lib
  1456.  
  1457.     SYNTAX
  1458.     #include <math.h>
  1459.     double a = cos(b);
  1460.     double c;
  1461.     float  c = fcos(d);
  1462.     double d;
  1463.  
  1464.     DESCRIPTION
  1465.     cos returns the cosine of a type double quantity. fcos is the same,
  1466.     except expects a type float.  These functions use radian measure.
  1467.  
  1468.     INPUTS
  1469.     double b;        double floating point value
  1470.  
  1471.     RESULTS
  1472.     double a;        result double floating point value
  1473.  
  1474.     SEE ALSO
  1475.     acos, asin, atan, exp, fabs, log, log10, pow, sin, sqrt, tan facos,
  1476.     fasin, fcos
  1477.  
  1478.     EXAMPLE
  1479.     /*
  1480.      *  compile with the math library -lm
  1481.      */
  1482.     #include <math.h>
  1483.     #include <stdio.h>
  1484.  
  1485.     main()
  1486.     {
  1487.        {
  1488.           double a = cos(0.25);
  1489.           printf("cos 0.25 = %lf\n", a);  /* 0.9689 */
  1490.        }
  1491.        {  /*  less accuracy   */
  1492.           float a = fcos(0.25);
  1493.           printf("cos 0.25 = %lf\n", (double)a);
  1494.        }
  1495.        return(0);
  1496.     }
  1497.  
  1498. dice/creat                                                        dice/creat
  1499.  
  1500.     FUNCTION
  1501.     create a file (UNIX)
  1502.  
  1503.     SYNTAX
  1504.     #include <fnctl.h>
  1505.     int fd = creat(file);
  1506.     char *file;
  1507.  
  1508.     DESCRIPTION
  1509.     creat creates a new file and returns a file descriptor for it. This
  1510.     call is equivalent to open(file,O_CREAT|O_TRUNC|O_RDWR); this is an
  1511.     obsolete function and should not be used.
  1512.  
  1513. dice/CreateDiceRexxPort                              dice/CreateDiceRexxPort
  1514.  
  1515.     FUNCTION
  1516.     Create an application ARexx port (DICE)
  1517.  
  1518.     SYNTAX
  1519.     #include <lib/rexx.h>
  1520.     short r = CreateDiceRexxPort(port, name)
  1521.     struct MsgPort *port;
  1522.     char *name;
  1523.  
  1524.     DESCRIPTION
  1525.     This call integrates any number of ARexx ports beyond the master port
  1526.     into DICE's ARexx system.  This call may be made from any point in
  1527.     your program.  After this call returns the message port will accept
  1528.     incomming ARexx messages.
  1529.  
  1530.     || NOTE: For simple programs you can simply use the master port
  1531.     || (RexxPort) that DICE sets up for you automatically and need not
  1532.     || bother with creating additional ports.  This call is more of use
  1533.     || in more complex programs which handle multiple projects
  1534.     || simultaniously.
  1535.  
  1536.     If you had declared RexxHostName as NULL causing DICE to not
  1537.     initialize an internal default RexxPort, you can pass NULL for port
  1538.     to initialize DICE's internal default RexxPort, thereby allowing
  1539.     PlaceRexxCommand() calls that specify a NULL port (i.e. to use DICE's
  1540.     internal default RexxPort).  You are not required to use DICE's
  1541.     internal message port, it is simply convenient.
  1542.  
  1543.     INPUTS
  1544.     struct MsgPort *port;
  1545.                 A blank msgPort structure (that is, totally
  1546.                 zero'd out). DICE will fill the structure with
  1547.                 appropriate values. DICE uses the same signal bit
  1548.                 as it allocated for the master port (RexxPort).
  1549.                 DICE makes this message port public through the
  1550.                 AddPort() call.
  1551.  
  1552.     char *name        A pointer to the name of the message port. DICE
  1553.                 adds a .NN extension to this name, finding a free
  1554.                 slot number when creating a public message port.
  1555.                 If you pass NULL for this field, DICE will create
  1556.                 a private message port suitable for handling
  1557.                 ARexx call-backs.  An error (-1) is returned if
  1558.                 no slots are available (all 99 are in use).  If
  1559.                 you had passed NULL for the port structure then
  1560.                 DICED will initialize RexxHostName to the
  1561.                 extended name.
  1562.  
  1563.     RESULTS
  1564.     int r;            the slot number for the port or -1 if an error
  1565.                 occured.
  1566.  
  1567.     SEE ALSO
  1568.     CreateGlobalDiceRexxPort, DeleteDiceRexxPort, GetDiceRexxPortSlot
  1569.  
  1570.     EXAMPLE
  1571.     See DICE ARexx Support in chapter
  1572.  
  1573. dice/CreateGlobalDiceRexxPort                  dice/CreateGlobalDiceRexxPort
  1574.  
  1575.     FUNCTION
  1576.     Create a global ARexx port (DICE)
  1577.  
  1578.     SYNTAX
  1579.     #include <lib/rexx.h>
  1580.     rc = CreateGlobalDiceRexxPort(port, name)
  1581.     int rc;
  1582.     struct MsgPort *port;
  1583.     char *name;
  1584.  
  1585.     DESCRIPTION
  1586.     CreateGlobalDiceRexxPort integrates any number of ARexx ports beyond
  1587.     the master port into DICE's ARexx system. This call may be made from
  1588.     any point in your program. After this call returns the message port
  1589.     will accept incomming ARexx messages.
  1590.  
  1591.     || NOTE: For simple programs you can simply use the master port
  1592.     || (RexxPort) that DICE sets up for you automatically and need not
  1593.     || bother with creating additional ports.  This call is more of use
  1594.     || in more complex programs which handle multiple projects
  1595.     || simultaniously.
  1596.  
  1597.     If you had declared RexxHostName as NULL causing DICE to not
  1598.     initialize an internal default RexxPort, you can pass NULL for
  1599.     msgPort to initialize DICE's internal default RexxPort, thereby
  1600.     allowing PlaceRexxCommand calls that specify a NULL port (i.e. to use
  1601.     DICE's internal default RexxPort).  You are not required to use
  1602.     DICE's internal message port, it is simply convenient.
  1603.  
  1604.     INPUTS
  1605.     struct MsgPort *port;
  1606.                 A blank msgPort structure (that is, totally
  1607.                 zero'd out). DICE will fill the structure with
  1608.                 appropriate values. DICE uses the same signal bit
  1609.                 as it allocated for the master port (RexxPort).
  1610.                 DICE will make this message port public through
  1611.                 the AddPort() call.
  1612.  
  1613.     char *name;        A pointer to the name of the message port.    DICE
  1614.                 uses this name verbatim.  An error (-1) is
  1615.                 returned if the port already exists.  If you had
  1616.                 passed NULL for the MsgPort structure DICE will
  1617.                 initialize RexxHostName to name.
  1618.  
  1619.     RESULTS
  1620.     int r;            0 for success, -1 for error
  1621.  
  1622.     SEE ALSO
  1623.     CreateDiceRexxPort, DeleteDiceRexxPort, GetDiceRexxPortSlot
  1624.  
  1625.     EXAMPLE
  1626.     See DICE ARexx Support in chapter
  1627.  
  1628. dice/ctime                                                        dice/ctime
  1629.  
  1630.     FUNCTION
  1631.     convert time into standard text (ANSI)
  1632.  
  1633.     SYNTAX
  1634.     #include <time.h>
  1635.     char *str = ctime(&t); time_t t;
  1636.  
  1637.     DESCRIPTION
  1638.     ctime converts a time pointer into ASCII text using the following
  1639.      format:
  1640.         Sun Dec 8 01:53:33 1987\n\0
  1641.     where \n stands for a newline character and \0 is terminating nul.
  1642.     The string is stored in a static buffer shared by both asctime and
  1643.     ctime and so will be overwritten whenever either function is called.
  1644.  
  1645.     INPUTS
  1646.     time_t *t;        pointer to a time_t value
  1647.  
  1648.     RESULTS
  1649.     char *str;        pointer to static string
  1650.  
  1651.     SEE ALSO
  1652.     time, localtime, asctime, strftime, ctime, clock
  1653.  
  1654.     EXAMPLE
  1655.     #include <stdio.h>
  1656.     #include <time.h>
  1657.  
  1658.     main()
  1659.     {
  1660.        time_t t = time(NULL);
  1661.        fputs(ctime(&t), stdout);
  1662.        return(0);
  1663.     }
  1664.  
  1665. dice/DeleteDiceRexxPort                              dice/DeleteDiceRexxPort
  1666.  
  1667.     FUNCTION
  1668.     Delete a DICE ARexx port (DICE)
  1669.  
  1670.     SYNTAX
  1671.     #include <lib/rexx.h>
  1672.     void DeleteDiceRexxPort(port)
  1673.     struct MsgPort *port;
  1674.  
  1675.     DESCRIPTION
  1676.     This call deletes a previously created DICE ARexx port. You may NOT
  1677.     delete any ARexx port while within DoRexxCommand().  This call may
  1678.     only be made from the top level of your program or you run the risk
  1679.     of deleted an ARexx port out from under yourself.
  1680.  
  1681.     ## WARNING: You may NOT delete the master ARexx port, only those you
  1682.     ## specifically create.
  1683.  
  1684.     This call automatically clears out any as yet unread messages on the
  1685.     port, removes the port from the public message list with RemPort(),
  1686.     and zero's the structure.
  1687.  
  1688.     INPUTS
  1689.     struct MsgPort *port;
  1690.                 The message port to delete.  You must have
  1691.                 created it using CreateGlobalDiceRexxPort or
  1692.                 CreateDiceRexxPort
  1693.  
  1694.     SEE ALSO
  1695.     CreateGlobalDiceRexxPort, CreateDiceRexxPort, GetDiceRexxPortSlot
  1696.  
  1697.     EXAMPLE
  1698.     See DICE ARexx Support in chapter
  1699.  
  1700. dice/dir                                                            dice/dir
  1701.  
  1702.     FUNCTION
  1703.     disk directory scanning (UNIX)
  1704.  
  1705.     SYNTAX
  1706.     #include <sys/dir.h>
  1707.     DIR *dirhan = opendir(path);
  1708.     struct direct *entry = readdir(dirhan);
  1709.     (void) rewinddir(dirhan);
  1710.     void
  1711.     closedir(dirhan);
  1712.     const char *path;
  1713.     DIR *dirhan;
  1714.  
  1715.     DESCRIPTION
  1716.     These are UNIX compatible directory scanning calls.  After opening a
  1717.     directory with opendir, you may scan it with successive calls to
  1718.     readdir until NULL is returned, then either rewinddir it for a
  1719.     rescan, or closedir it when done.  The DIR structure is private to
  1720.     the library.  Valid fields within struct direct are d_name (the file
  1721.     name), and d_namlen (the length of the file name, not usually
  1722.     needed).  You can chdir into the directory and stat each entry to
  1723.     obtain additional information.    Note that while the UNIX directory
  1724.     scanning routines will not be as efficient as the Amiga directory
  1725.     scanning routines, the UNIX directory scanning routines are portable.
  1726.  
  1727.     || NOTE: Unlike the Amiga directory scanning routines that use Amiga
  1728.     || File Locks, these calls will automatically deallocate resources if
  1729.     || the program terminates. rewinddir's prototype returns an int.
  1730.     || This is for internal use only.  You should never use rewinddir's
  1731.     || return value yourself.
  1732.  
  1733.     SEE ALSO
  1734.     chdir
  1735.  
  1736.     EXAMPLE
  1737.     #include <stdio.h>
  1738.     #include <sys/dir.h>
  1739.     main(int ac, char*av[])
  1740.     {
  1741.        DIR *dir;
  1742.        if (ac == 1)
  1743.        {
  1744.           puts("test dir");
  1745.           exit(1);
  1746.        }
  1747.        if (dir = opendir(av[1]))
  1748.        {
  1749.           struct direct *entry;
  1750.           while (entry = readdir(dir))
  1751.           {
  1752.          printf("%s\n", entry->d_name);
  1753.           }
  1754.           closedir(dir);
  1755.        }
  1756.        return(0);
  1757.     }
  1758.  
  1759. dice/_divs,_divu                                            dice/_divs,_divu
  1760.  
  1761.     FUNCTION
  1762.     Signed and unsigned long divide (DICE)
  1763.  
  1764.     DESCRIPTION
  1765.     DICE uses these assembly level functions whenever it needs to do long
  1766.     division; they are not callable from C.
  1767.  
  1768.     INPUTS
  1769.     D0            32 bit signed/unsigned integer
  1770.  
  1771.     D1            32 bit signed/unsigned integer
  1772.  
  1773.     RESULTS
  1774.     D0            D0 divided by D1
  1775.  
  1776.     SEE ALSO
  1777.     _mods, _modu, _muls, _mulu
  1778.  
  1779. dice/DoRexxCommand                                        dice/DoRexxCommand
  1780.  
  1781.     FUNCTION
  1782.     Parse an incomming ARexx command (DICE)
  1783.  
  1784.     SYNTAX
  1785.     #include <lib/rexx.h>
  1786.     /* YOU DECLARE THIS IN YOUR CODE */
  1787.     long DoRexxCommand(msg, port, arg0, pres)
  1788.     void *msg;
  1789.     struct MsgPort *port;
  1790.     char *arg0;
  1791.     char **pres;
  1792.     {
  1793.        long rc = 0;
  1794.        *pres = "return string";
  1795.        return(rc);
  1796.     }
  1797.  
  1798.     DESCRIPTION
  1799.     DoRexxCommand is a routine that YOU supply to process incomming ARexx
  1800.     requests.  DICE will call your routine for any requests it processes
  1801.     with ProcessRexxCommands as well as for any requests that come in
  1802.     during processing of a PlaceRexxCommand. DICE presets pres to NULL.
  1803.  
  1804.     To return an error simply return a non-zero error code.
  1805.  
  1806.     To return a string, set pres to point to the string and return 0.
  1807.     DICE will make a copy of the string to return to ARexx.  Note that
  1808.     the application requesting the string will not see if if they have
  1809.     not requested 'OPTIONS RESULTS' as part of their processing.
  1810.  
  1811.     ## WARNING: Because your procedure must return before DICE can
  1812.     ## process the string, you MUST not assign pres to any local stack
  1813.     ## variables.  The resulting crash can be quite spectacular.
  1814.  
  1815.     INPUTS
  1816.     void *msg;        Incomming ARexx message if necessary.
  1817.  
  1818.     struct MsgPort *port;
  1819.                 Port that the message came in on.
  1820.  
  1821.     char *arg0;        The ARexx command that is to be processed.    Your
  1822.                 code must parse this in whatever way you want.
  1823.  
  1824.     char **pres;        Place to store result string.
  1825.  
  1826.     RESULTS
  1827.     int rc;         Return code to be passed to the application
  1828.                 requesting the ARexx command.
  1829.  
  1830.     SEE ALSO
  1831.     PlaceRexxCommand, PlaceRexxCommandDirect, ProcessRexxCommands
  1832.  
  1833.     EXAMPLE
  1834.     See DICE ARexx Support in chapter
  1835.  
  1836. dice/exit                                                          dice/exit
  1837.  
  1838.     FUNCTION
  1839.     Exit from a program 'nicely' (ANSI)
  1840.  
  1841.     SYNTAX
  1842.     #include <stdlib.h>
  1843.     (void) exit(code)
  1844.  
  1845.     DESCRIPTION
  1846.     exit exits the program and returns the specified exit code. Normally
  1847.     you pass 0 to indicate no errors, and a positive number to indicate a
  1848.     program error to the parent.  exit closes all stdio file pointers,
  1849.     low level file descriptors, perhaps a few other things, and then
  1850.     finally calls _exit with the code. If you use main you should call
  1851.     exit to exit the program or return an error code from main.  If you
  1852.     use the _main entry point (only for programmers dead set on
  1853.     optimizing executable size and using only system library calls) you
  1854.     should use the _exit exit point.
  1855.  
  1856.     SEE ALSO
  1857.     main, _main, _exit
  1858.  
  1859.     EXAMPLE
  1860.     main(int ac, char *av[])
  1861.     {
  1862.        if (ac <= 1) {
  1863.           puts("Sorry, you must supply a parameter!");
  1864.           exit(1);
  1865.        }
  1866.        puts("Thanks!");
  1867.        exit(0);
  1868.     }
  1869.  
  1870. dice/_exit                                                        dice/_exit
  1871.  
  1872.     FUNCTION
  1873.     exit from a program without bothering to release resources (ANSI)
  1874.  
  1875.     SYNTAX
  1876.     #include <stdlib.h>
  1877.     (void) _exit(code)
  1878.     int code;
  1879.  
  1880.     DESCRIPTION
  1881.     _exit exits from a program and returns the specified exit code.
  1882.     Normally you pass 0 to indicate no errors, a positive number to
  1883.     indicate a program error to the parent.  Note that since auto-init
  1884.     opened libraries are closed in the startup module (c.o),
  1885.     automatically opened libraries will be automatically closed for you.
  1886.     However, any libraries you manually declare the library base variable
  1887.     for and manually open must be closed by you.  You should only call
  1888.     _exit if you used the _main entry point (instead of the usual main),
  1889.     and then only after releasing all resources (such as file handles
  1890.     opened with open).
  1891.  
  1892.     INPUTS
  1893.     int code;        code is a value that is passed back to caller
  1894.  
  1895.     SEE ALSO
  1896.     main, _main, exit
  1897.  
  1898.     EXAMPLE
  1899.     _main()
  1900.     {
  1901.        Write(Output(), "Ouch!!\n", 7);
  1902.        _exit(20); /* 20 - Severe Error */
  1903.     }
  1904.  
  1905. dice/exp                                                            dice/exp
  1906.  
  1907.     FUNCTION
  1908.     return e to the power of the double quantity (ANSI)
  1909.  
  1910.     LIBRARY
  1911.     m.lib
  1912.  
  1913.     SYNTAX
  1914.     #include <math.h>
  1915.     double a = exp(b);
  1916.     double b;
  1917.  
  1918.     DESCRIPTION
  1919.     exp returns e to the power of the floating point quantity.
  1920.  
  1921.     INPUTS
  1922.     double b;        double floating point value
  1923.  
  1924.     RESULTS
  1925.     double a;        result double floating point value
  1926.  
  1927.     SEE ALSO
  1928.     acos, asin, atan, cos, fabs, log, log10, pow, sin,  sqrt, tan facos,
  1929.     fasin
  1930.  
  1931.     EXAMPLE
  1932.     /*
  1933.      *  compile with the math library -lm
  1934.      */
  1935.     #include <math.h>
  1936.     #include <stdio.h>
  1937.     main()
  1938.     {
  1939.        {
  1940.           double a = exp(0.25);
  1941.           printf("exp 0.25 = %lf\n", a);
  1942.        }
  1943.        {  /*  less accuracy   */
  1944.           float a = fexp(0.25);
  1945.           printf("exp 0.25 = %lf\n", (double)a);
  1946.        }
  1947.        return(0);
  1948.     }
  1949.  
  1950. dice/expand_args                                            dice/expand_args
  1951.  
  1952.     FUNCTION
  1953.     expand command line argument wildcards (DICE)
  1954.  
  1955.     SYNTAX
  1956.     #include <stdio.h>
  1957.     int error = expand_args(xac, xav, &ac, &av);
  1958.     int xac;
  1959.     const char **xav;
  1960.     int ac;
  1961.     char **av;
  1962.  
  1963.     DESCRIPTION
  1964.     expand_args is a powerful and convenient function.  A few lines of
  1965.     simple code allow your program to have full wildcard support under
  1966.     any version of the OS.    expand_args takes an argc/argv list and
  1967.     expands any wildcard arguments by scanning the appropriate directory.
  1968.     It  malloc's however much memory it needs to create the new list and
  1969.     ignores xav[0] (that is, it just copies it to the returned av[0]
  1970.     without doing a wildcard expansion). expand_args fills in the ac and
  1971.     av variables with its own malloc'd version of the argument list, now
  1972.     completely expanded.  There is no limit to the number of files that
  1973.     may be in this result list (you could conceivably have thousands).
  1974.     expand_args may be used to expand arbitrary AmigaDOS wildcards and is
  1975.     not limited to an anchored search.  For example, you could specify:
  1976.     sys:#?/#? in which case a list of a second level files/dirs will be
  1977.     generated. In the above case, expand_args scans sys, then scans any
  1978.     sub directories found in sys.  Generic AmigaDOS wildcarding is used
  1979.     and incredibly complex wildcards may be specified.  Please note,
  1980.     however, that any wildcard elements containing #? in combination with
  1981.     other elements (such as (a|b|c)) will cause huge amounts of stack to
  1982.     be used and also quite a bit of memory during the scan. expand_args
  1983.     limits itself to 4K of stack before giving up. Any program that uses
  1984.     expand_args should be run with at least 8K of stack.
  1985.  
  1986.     INPUTS
  1987.     int  xac;        original argc
  1988.  
  1989.     char **xav;        original argv
  1990.  
  1991.     int  *ac;        pointer to new argc
  1992.  
  1993.     char ***av;        pointer to new argv
  1994.  
  1995.     RESULTS
  1996.     int error;        0 if all went well, non-zero otherwise
  1997.  
  1998.     EXAMPLE
  1999.     #include <stdio.h>
  2000.     main(int xac, char **xav)
  2001.     {
  2002.        int ac, i, error;
  2003.        char **av;
  2004.        int error = expand_args(xac, xav, &ac, &av);
  2005.        for (i = 1; i < ac; ++i) {
  2006.           printf("%s\n", av[i]);
  2007.        }
  2008.     }    /* expand_args #?.c */
  2009.  
  2010. dice/fabs                                                          dice/fabs
  2011.  
  2012.     FUNCTION
  2013.     return the absolute value of a double quantity (ANSI)
  2014.  
  2015.     LIBRARY
  2016.     m.lib
  2017.  
  2018.     SYNTAX
  2019.     #include <math.h>
  2020.     double a = fabs(b);
  2021.     double b;
  2022.  
  2023.     DESCRIPTION
  2024.     fabs returns the absolute value of a floating point quantity.
  2025.  
  2026.     INPUTS
  2027.     float d;        float floating point value
  2028.  
  2029.     RESULTS
  2030.     int arg;        control argument
  2031.  
  2032.     int r;            result, error if less than 0.
  2033.  
  2034.     EXAMPLE
  2035.     /*
  2036.      *  compile with the math library -lm
  2037.      */
  2038.     #include <math.h>
  2039.     #include <stdio.h>
  2040.     main()
  2041.     {
  2042.        {
  2043.           double a = fabs(-0.25);
  2044.           printf("fabs -0.25 = %lf\n", a); /*  0.25  */
  2045.        }
  2046.        {  /*  less accuracy   */
  2047.           float a = ffabs(-0.25);
  2048.           printf("fabs -0.25 = %lf\n", (double)a);
  2049.        }
  2050.        return(0);
  2051.     }
  2052.  
  2053. dice/facos                                                        dice/facos
  2054.  
  2055.     FUNCTON
  2056.     float arc cosine (UNIX)
  2057.  
  2058.     LIBRARY
  2059.     m.lib
  2060.  
  2061.     SYNTAX
  2062.     #include <math.h>
  2063.     float  c = facos(d);
  2064.     float  d;
  2065.  
  2066.     DESCRIPTION
  2067.     facos returns the arc cosine of a floating point quantity.
  2068.  
  2069.     INPUTS
  2070.     float d;        float floating point value
  2071.  
  2072.     RESULTS
  2073.     result float;        floating point value
  2074.  
  2075.     SEE ALSO
  2076.     acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan,
  2077.     fasin
  2078.  
  2079.     EXAMPLE
  2080.     /*
  2081.      *  compile with the math library -lm
  2082.      */
  2083.     #include <math.h>
  2084.     #include <stdio.h>
  2085.     main()
  2086.     {
  2087.        {
  2088.            double a = acos(0.25);
  2089.            printf("acos 0.25 = %lf\n", a); /* 1.318   */
  2090.        }
  2091.        {   /* less accuracy   */
  2092.            float a = facos(0.25);
  2093.            printf("acos 0.25 = %lf\n", (double)a);
  2094.        }
  2095.        return(0);
  2096.     }
  2097.  
  2098. dice/fasin                                                        dice/fasin
  2099.  
  2100.     FUNCTION
  2101.     return arc sine of a float quantity (UNIX)
  2102.  
  2103.     LIBRARY
  2104.     m.lib
  2105.  
  2106.     SYNTAX
  2107.     #include <math.h>
  2108.     float  c = fasin(d);
  2109.     float  d;
  2110.  
  2111.     DESCRIPTION
  2112.     fasin returns the arc sine of a floating point quantity.
  2113.  
  2114.     INPUTS
  2115.     float d;        float floating point value
  2116.  
  2117.     RESULTS
  2118.     float c;        result float  floating point value
  2119.  
  2120.     SEE ALSO
  2121.     acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan
  2122.     facos
  2123.  
  2124.     EXAMPLE
  2125.     /*
  2126.      *  compile with the math library -lm
  2127.      */
  2128.     #include <math.h>
  2129.     #include <stdio.h>
  2130.  
  2131.     main()
  2132.     {
  2133.        {
  2134.           double a = asin(0.25);
  2135.           printf("asin 0.25 = %lf\n", a);  /* 0.2527 */
  2136.        }
  2137.        {  /*  less accuracy */
  2138.           float a = fasin(0.25);
  2139.           printf("asin 0.25 = %lf\n", (double)a);
  2140.        }
  2141.        return(0);
  2142.     }
  2143.  
  2144. dice/fatan                                                        dice/fatan
  2145.  
  2146.     FUNCTION
  2147.     return arc tan of a float quantity (UNIX)
  2148.  
  2149.     LIBRARY
  2150.     m.lib
  2151.  
  2152.     SYNTAX
  2153.     #include <math.h>
  2154.     float  c = fatan(d); float  d;
  2155.  
  2156.     DESCRIPTION
  2157.     fatan returns the arc tan of a floating point quantity.
  2158.  
  2159.     INPUTS
  2160.     float d;        float floating point value
  2161.  
  2162.     RESULTS
  2163.     float c;        result float floating point value
  2164.  
  2165.     SEE ALSO
  2166.     acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan
  2167.     facos, fasin
  2168.  
  2169.     EXAMPLE
  2170.     /*
  2171.      *  compile with the math library -lm
  2172.      */
  2173.     #include <math.h>
  2174.     #include <stdio.h>
  2175.     main()
  2176.     {
  2177.        {
  2178.           double a = atan(0.25);
  2179.           printf("atan 0.25 = %lf\n", a);  /* 0.245   */
  2180.        }
  2181.        {  /* less accuracy     */
  2182.           float a = fatan(0.25);
  2183.           printf("atan 0.25 = %lf\n", (double)a);
  2184.        }
  2185.        return(0);
  2186.     }
  2187.  
  2188. dice/fclose                                                      dice/fclose
  2189.  
  2190.     FUNCTION
  2191.     close a file pointer (ANSI)
  2192.  
  2193.     SYNTAX
  2194.     #include <stdio.h>
  2195.     int error = fclose(fp);
  2196.     FILE    *fp;
  2197.  
  2198.     DESCRIPTION
  2199.     fclose flushes any data remaining in the file pointer's output buffer
  2200.     to the file and then closes the file. The file pointer is no longer
  2201.     valid. fclose returns any error condition that occurred while it was
  2202.     flushing the buffered data to the file.  The file is closed even if
  2203.     an error occurred.
  2204.  
  2205.     || NOTE: You can fclose(stdin), fclose(stdout), and fclose(stderr) to
  2206.     || save space or detach your process from the console (i.e. allow the
  2207.     || console window to be closed).
  2208.  
  2209.     ## WARNING: If you fclose stdin, stdout, and stderr with the
  2210.     ## intention of removing all references to the console window, you
  2211.     ## must put a NULL in your processes pr_ConsoleTask field. Otherwise,
  2212.     ## the console window will be able to close, but your process will
  2213.     ## still have a reference to the now non-existent window.  Refer to
  2214.     ## the file_pointer manual page for general information
  2215.  
  2216.     INPUTS
  2217.     FILE *F;        file pointer
  2218.  
  2219.     RESULTS
  2220.     int error;        error on fclose, or 0 if none
  2221.  
  2222.     SEE ALSO
  2223.     fopen, fread, fwrite, fgets, fputs
  2224.  
  2225. dice/fcntl                                                        dice/fcntl
  2226.  
  2227.     FUNCTION
  2228.     file control on a file (UNIX)
  2229.  
  2230.     SYNTAX
  2231.     #include <fcntl.h>
  2232.     int r = fcntl(fd, req, arg)
  2233.     int fd;
  2234.     int req;
  2235.     int arg;
  2236.  
  2237.     DESCRIPTION
  2238.     fcntl may be used to control various aspects of an fd and is a higher
  2239.     level call than ioctl.    Currently, nothing truly significant can be
  2240.     accomplished by a fcntl call for files.  However, fcntl fully
  2241.     supports programmer simulated file descriptors.
  2242.  
  2243.     || NOTE: Refer to the file_descriptor manual page for general
  2244.     || information Unlike file pointers and file handles, the file
  2245.     || descriptor is checked for validity and if illegal, an error will
  2246.     || be returned.
  2247.  
  2248.     INPUTS
  2249.     int fd;         file descriptor to operate on
  2250.  
  2251.     int req;        request from <fcntl.h> (F_* defines)
  2252.  
  2253.     int arg;        control argument
  2254.  
  2255.     RESULTS
  2256.     int r;            result, error if less than 0
  2257.  
  2258.     SEE ALSO
  2259.     close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  2260.     rmdir, unlink, write
  2261.  
  2262. dice/fdopen                                                      dice/fdopen
  2263.  
  2264.     FUNCTION
  2265.     associate a file pointer with an open file descriptor (UNIX)
  2266.  
  2267.     SYNTAX
  2268.     #include <stdio.h>
  2269.     FILE *fp = fdopen(fd, modes);
  2270.     int fd; char *modes;
  2271.  
  2272.     DESCRIPTION
  2273.     fdopen associates an open file descriptor with a file pointer.
  2274.  
  2275.     || NOTE: Once fclose is used, the file pointer will also close the
  2276.     || file descriptor.  Refer to the fopen manual page for a description
  2277.     || of available modes. Also, when you use fdopen the file will not be
  2278.     || truncated and if you specify mode a for append, the file
  2279.     || descriptor must have been opened with the O_APPEND flag.  That is,
  2280.     || the mode string should be similar to the open flags that were used
  2281.     || to open the file descriptor. Refer to the file_pointer manual page
  2282.     || for general information
  2283.  
  2284.     INPUTS
  2285.     int fd;         file descriptor to associated with a new file
  2286.                 pointer
  2287.  
  2288.     char *modes;        modes string, such as "r+".
  2289.  
  2290.     RESULTS
  2291.     FILE *fp;        new file pointer or NULL if an error occurred
  2292.  
  2293.     SEE ALSO
  2294.     fopen, fread, fwrite, fgets, fputs
  2295.  
  2296. dice/fdtofh                                                      dice/fdtofh
  2297.  
  2298.     FUNCTION
  2299.     return AmigaDOS file handle for file descriptor (AmigaDOS)
  2300.  
  2301.     SYNTAX
  2302.     #include <stdio.h>
  2303.     BPTR fh = fdtofh(fd);
  2304.     int fd;
  2305.  
  2306.     DESCRIPTION
  2307.     fdtofh returns the AmigaDOS file handle associated with a file
  2308.     descriptor or NULL if the file descriptor is illegal or simulated.
  2309.     You may then make AmigaDOS library calls using the file handle.
  2310.  
  2311.     INPUTS
  2312.     int fd;         file descriptor
  2313.  
  2314.     RESULTS
  2315.     BPTR fh;        associated file handle or NULL
  2316.  
  2317.     SEE ALSO
  2318.     close, creat, fcntl, ioctl, isatty, lseek, mkdir, open, read, rmdir,
  2319.     unlink, write
  2320.  
  2321.     EXAMPLE
  2322.     #include <stdio.h>
  2323.     main()
  2324.     {
  2325.     FILE * fh;
  2326.        write(1, "Quayle\n", 6);
  2327.        if( fh = fdtofh(1) )  /* Example Only! */
  2328.           Write(fh, "Bait\n", 6);
  2329.        return(0);
  2330.     }
  2331.  
  2332. dice/feof                                                          dice/feof
  2333.  
  2334.     FUNCTION
  2335.     test a file pointer for End Of File (ANSI)
  2336.  
  2337.     SYNTAX
  2338.     #include <stdio.h>
  2339.     int r = feof(fp);
  2340.     (MACRO) FILE *fp;
  2341.  
  2342.     DESCRIPTION
  2343.     feof returns the EOF  status of a file pointer.  The status is not
  2344.     changed by this macro.    0 is returned if no EOF condition exists,
  2345.     non-zero if an EOF condition exists (not necessarily 1 or -1, just
  2346.     non-zero).  Use clearerr to clear the EOF condition. Note than fseek
  2347.     and rewind also clear an EOF condition.
  2348.  
  2349.     INPUTS
  2350.     FILE *fp;        file pointer
  2351.  
  2352.     RESULTS
  2353.     int r;            0 if no EOF condition exists, != 0 if an EOF
  2354.                 condition exists (not necessarily 1 or -1).
  2355.  
  2356.     SEE ALSO
  2357.     fopen, fclose, fread, fwrite, fgets, fputs, file_pointer
  2358.  
  2359. dice/ferror                                                      dice/ferror
  2360.  
  2361.     FUNCTION
  2362.     return ERROR condition for file pointer (ANSI)
  2363.  
  2364.     SYNTAX
  2365.     #include <stdio.h>
  2366.     int r = ferror(fp); /* MACRO */
  2367.     FILE *fp;
  2368.  
  2369.     DESCRIPTION
  2370.     ferror returns the ERROR status of a file pointer.  The status is not
  2371.     changed by this macro.    0 is returned if no ERROR condition exists,
  2372.     non-zero if an ERROR condition exists (not necessarily 1 or -1, just
  2373.     non-zero).
  2374.  
  2375.     INPUTS
  2376.     FILE *fp;        file pointer
  2377.  
  2378.     RESULTS
  2379.     int r;            0 if no ERROR condition exists, != 0 if an ERROR
  2380.                 condition exists (not necessarily 1 or -1).
  2381.  
  2382.     SEE ALSO
  2383.     fopen, fclose, fread, fwrite, fgets, fputs, file_pointer
  2384.  
  2385. dice/fexp                                                          dice/fexp
  2386.  
  2387.     FUNCTION
  2388.     return e to the power of the float quantity (UNIX)
  2389.  
  2390.     LIBRARY
  2391.     m.lib
  2392.  
  2393.     SYNTAX
  2394.     #include <math.h>
  2395.     float  c = fexp(d);
  2396.     float  d;
  2397.  
  2398.     DESCRIPTION
  2399.     fexp returns e to the power of the floating point quantity
  2400.  
  2401.     INPUTS
  2402.     float d;        float floating point value
  2403.  
  2404.     RESULTS
  2405.     float c;        result float  floating point value
  2406.  
  2407.     SEE ALSO
  2408.     acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan,
  2409.     facos, fasin
  2410.  
  2411.     EXAMPLE
  2412.     /*
  2413.      *  compile with the math library -lm
  2414.      */
  2415.     #include <math.h>
  2416.     #include <stdio.h>
  2417.  
  2418.     main()
  2419.     {
  2420.        {
  2421.           double a = exp(0.25);
  2422.           printf("exp 0.25 = %lf\n", a);
  2423.           printf("exp 0    = %lf\n", (double)exp(0) );
  2424.        }
  2425.        {  /*  less accuracy   */
  2426.           float a = fexp(0.25);
  2427.           printf("exp 0.25 = %lf\n", (double)a);
  2428.        }
  2429.        return(0);
  2430.     }
  2431.  
  2432. dice/ffabs                                                        dice/ffabs
  2433.  
  2434.     FUNCTION
  2435.     return the absolute value of a float (UNIX)
  2436.  
  2437.     LIBRARY
  2438.     m.lib
  2439.  
  2440.     SYNTAX
  2441.     #include <math.h>
  2442.     float  c = ffabs(d);
  2443.     float  d;
  2444.  
  2445.     DESCRIPTION
  2446.     ffabs returns the absolute value of a floating point quantity.
  2447.  
  2448.     INPUTS
  2449.     float d;        float floating point value
  2450.  
  2451.     RESULTS
  2452.     int arg;        control argument
  2453.  
  2454.     int r;            result, error if less than 0.
  2455.  
  2456.     SEE ALSO
  2457.     acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan,
  2458.     facos, fasin
  2459.  
  2460.     EXAMPLE
  2461.     /*
  2462.      *  compile with the math library -lm
  2463.      */
  2464.     #include <math.h>
  2465.     #include <stdio.h>
  2466.     main()
  2467.     {
  2468.        {
  2469.            double a = fabs(-0.25);
  2470.            printf("fabs -0.25 = %lf\n", a); /*  0.25  */
  2471.        }
  2472.        {  /*  less accuracy   */
  2473.           float a = ffabs(-0.25);
  2474.           printf("fabs -0.25 = %lf\n", (double)a);
  2475.        }
  2476.        return(0);
  2477.     }
  2478.  
  2479. dice/fflush                                                      dice/fflush
  2480.  
  2481.     FUNCTION
  2482.     flush buffers to file (ANSI)
  2483.  
  2484.     SYNTAX
  2485.     #include <stdio.h>
  2486.     int error = fflush(fp);
  2487.     FILE *fp;
  2488.  
  2489.     DESCRIPTION
  2490.     fflush writes out any buffered data out to the file descriptor
  2491.     associated with the file pointer. Normally a file is either
  2492.     unbuffered, line buffered, or fully buffered;  fflush is useful in
  2493.     the latter two cases as is shown by the example. The function will
  2494.     return -1 if a write error occurred, 0 if no error occurred.
  2495.  
  2496.     || NOTE: Refer to the file_pointer manual page for general
  2497.     || information.
  2498.  
  2499.     INPUTS
  2500.     FILE *fp;        file pointer
  2501.  
  2502.     RESULTS
  2503.     int  error;        0 if no error, -1 on error.
  2504.  
  2505.     SEE ALSO
  2506.     fopen, fclose, fread, fwrite, fgets, fputs
  2507.  
  2508.     EXAMPLE
  2509.     /*
  2510.      *  Since text to stdout is normally line buffered,
  2511.      *  if we do not write out a newline '\n' then the
  2512.      *  line is still buffered in memory and we have to
  2513.      *  fflush() to write it out.
  2514.      */
  2515.     #include <stdio.h>
  2516.     main()
  2517.     {
  2518.        char buf[256];
  2519.        printf("Enter a number -");
  2520.        fflush(stdout);
  2521.        fgets(buf, sizeof(buf), stdin);
  2522.        printf("Munch Munch...");
  2523.        fflush(stdout);
  2524.        sleep(1);
  2525.        puts("Thanks!");
  2526.     }
  2527.  
  2528. dice/fgetc,getc                                              dice/fgetc,getc
  2529.  
  2530.     FUNCTION
  2531.     fgetc: get a single character (ANSI)
  2532.     getc: get a single character from a file pointer (ANSI)
  2533.  
  2534.     SYNTAX
  2535.     #include <stdio.h>
  2536.     int c = fgetc(fp);
  2537.     int c = getc(fp); /* MACRO */
  2538.     FILE *fp;
  2539.  
  2540.     DESCRIPTION
  2541.     getc and fgetc both read a single character from a file pointer.  The
  2542.     value returned is actually an int because EOF (-1) must be
  2543.     differentiated from a 255.  Each returns an integer 0-255 or EOF (-1)
  2544.     if an end of file occurs.
  2545.  
  2546.     || NOTE: Refer to the file_pointer manual page for general
  2547.     || information.
  2548.  
  2549.     INPUTS
  2550.     FILE *fp;        file pointer
  2551.  
  2552.     RESULTS
  2553.     int c;            character 0 to 255, or EOF (-1).
  2554.  
  2555.     SEE ALSO
  2556.     putc, fputc, fread, fwrite
  2557.  
  2558.     EXAMPLE
  2559.     /*
  2560.      *  copy stdin to stdout using getc/putc.  Normally
  2561.      *  one uses fread/fwrite, but I'll save that for the
  2562.      *  fread manual page.
  2563.      *  Note that I output the initial message to stderr so
  2564.      *  it does not get stuck into stdout in case the user
  2565.      *  has redirected stdout.
  2566.      */
  2567.     #include <stdio.h>
  2568.     main()
  2569.     {
  2570.        int c;
  2571.        fputs("Type a couple of lines, then ^\\ (EOF)\n",
  2572.           stderr);
  2573.        while ((c = getc(stdin)) != EOF)
  2574.        {
  2575.            putc(c, stdout);
  2576.        }
  2577.        return(0);
  2578.     }
  2579.  
  2580. dice/fgetpos                                                    dice/fgetpos
  2581.  
  2582.     FUNCTION
  2583.     get current file position (ANSI)
  2584.  
  2585.     SYNTAX
  2586.     #include <stdio.h>
  2587.     int error = fgetpos(fp, &pos);
  2588.     fpos_t pos;
  2589.  
  2590.     DESCRIPTION
  2591.     fgetpos returns the current seek position and is roughly equivalent
  2592.     to ftell.  fgetpos is a new ANSI call to better support C compilers
  2593.     that use 16 bit integers.  DICE uses 32 bit integers so fgetpos is
  2594.     not so useful.    fgetpos takes a file pointer and the address of a
  2595.     fpos_t type (a long).  It fills the fpos_t variable with the current
  2596.     file position and returns 0 if all went well, non-zero if an error
  2597.     occurred.
  2598.  
  2599.     || NOTE: Refer to the file_pointer manual page for general
  2600.     || information.
  2601.  
  2602.     INPUTS
  2603.     FILE *fp;        file pointer
  2604.  
  2605.     fpos_t *pos;        pointer to an fpos_t type that the position is
  2606.                 loaded into.
  2607.  
  2608.     RESULTS
  2609.     int error;        0 if no error, non-zero on error
  2610.  
  2611.     SEE ALSO
  2612.     ftell, rewind, fseek, rewind
  2613.  
  2614.     EXAMPLE
  2615.     /*
  2616.     **  Return the length of the file specified on the
  2617.     **  command line. */
  2618.     #include <stdio.h>
  2619.     main(int ac, char*av[])
  2620.     {
  2621.        FILE *fp;
  2622.        fpos_t off;
  2623.        if (ac == 1) {
  2624.           puts("Expected a filename argument");
  2625.           exit(1);
  2626.        }
  2627.        fp = fopen(av[1], "r");
  2628.        if (fp == NULL) {
  2629.           printf("Unable to open %s\n", av[1]);
  2630.           exit(5);
  2631.        }
  2632.        fseek(fp, 0L, SEEK_END);
  2633.        if (fgetpos(fp, &off)) {
  2634.           puts("Error getting file position");
  2635.           exit(20);
  2636.        }
  2637.        fclose(fp);
  2638.        printf("File %s is %d bytes long\n", av[1], off);
  2639.        return(0);
  2640.     }
  2641.  
  2642. dice/fgets                                                        dice/fgets
  2643.  
  2644.     FUNCTION
  2645.     get a line from a file pointer (ANSI)
  2646.  
  2647.     SYNTAX
  2648.     #include <stdio.h>
  2649.     char *ptr = fgets(buf, maxlen, fp);
  2650.     char *buf;
  2651.     int maxlen;
  2652.     FILE *fp;
  2653.  
  2654.     DESCRIPTION
  2655.     fgets gets a line from the specified file pointer, returning the
  2656.     first argument (buf) or NULL if an error or EOF occurs. fgets stores
  2657.     the line in buf, up to maxlen characters. This maximum includes a
  2658.     terminating newline '\n' and NULL '\0'. If more than maxlen-1
  2659.     characters are in the line fgets will terminate operation and put a
  2660.     NULL as the last character (so the buffer will still be a valid
  2661.     string). It is common to become confused by these functions:
  2662.  
  2663.  gets, puts
  2664.         These functions strip newline on input, add newline on output.
  2665.         gets works on stdin, puts on stdout.
  2666.  
  2667.  fgets, fputs
  2668.         These functions leave newlines alone on input, don't add to the
  2669.         output. Any file pointer, including stdin and stdout may be
  2670.         specified.
  2671.  
  2672.         || NOTE: Refer to the file_pointer manual page for general
  2673.         || information.
  2674.  
  2675.     INPUTS
  2676.     char *buf;        buffer
  2677.  
  2678.     int  maxlen;        maximum buffer size
  2679.  
  2680.     FILE *fp;        file pointer
  2681.  
  2682.     RESULTS
  2683.     char *ptr;        buf if all is well, or NULL if error or EOF
  2684.  
  2685.     SEE ALSO
  2686.     gets, puts, fputs, fread, getc, fgetc
  2687.  
  2688.     EXAMPLE
  2689.     #include <stdio.h>
  2690.     main()
  2691.     {
  2692.        unsigned char buf[128];
  2693.        short i;
  2694.        printf("Enter a line - ");
  2695.        fflush(stdout);
  2696.        if (fgets(buf, sizeof(buf), stdin) == NULL)
  2697.           exit(1);
  2698.        printf("In Hex: ");
  2699.        for (i = 0; buf[i]; ++i) printf(" %02x", buf[i]);
  2700.        puts("");
  2701.        return(0);
  2702.     }
  2703.  
  2704. dice/fhprintf                                                  dice/fhprintf
  2705.  
  2706.     FUNCTION
  2707.     formatted printing to a DOS file handle (AmigaDOS)
  2708.  
  2709.     SYNTAX
  2710.     #include <stdio.h>
  2711.     int n = fhprintf(fh, ctl, ...);
  2712.     BPTR fh;
  2713.     const char *ctl;
  2714.  
  2715.     DESCRIPTION
  2716.     fhprintf provides a method of using DICE's pfmt lib to do formatted
  2717.     printing to a file handle instead of a stdio file pointer. Output is
  2718.     unbuffered and thus not very efficient, but the call can be extremely
  2719.     useful when debugging libraries and such. If you have just a few
  2720.     things to print, and want to save the space the entire stdio package
  2721.     takes, you could use this function and _main.
  2722.  
  2723.     INPUTS
  2724.     BPTR fh;        DOS file handle
  2725.  
  2726.     const char *ctl;    format string, see printf()
  2727.  
  2728.     RESULTS
  2729.     int n;            number of characters output
  2730.  
  2731.     SEE ALSO
  2732.     printf, sprintf, vsprintf, fprintf, vfprintf, _main
  2733.  
  2734.     EXAMPLE
  2735.     void _main(int ac, char**av)
  2736.     {
  2737.        fhprintf(Output(), "The answer is %d!\n", 42);
  2738.     }
  2739.  
  2740. dice/file_descriptor                                    dice/file_descriptor
  2741.  
  2742.     FUNCTION
  2743.     file descriptor
  2744.  
  2745.     DESCRIPTION
  2746.     A file descriptor is the lowest portable access to the file system a
  2747.     C program may make.  File descriptors are used with open, read,
  2748.     write, close, etc.  A file descriptor is unbuffered (that is, every
  2749.     operation goes to the kernel and does not get buffered locally).
  2750.  
  2751.     || NOTE: Remember that a file descriptor is different from a stdio
  2752.     || file pointer (see the file_pointer manual page) and an AmigaDOS
  2753.     || file handle.
  2754.  
  2755. dice/fileno                                                      dice/fileno
  2756.  
  2757.     FUNCTION
  2758.     return file descriptor given a file pointer (UNIX)
  2759.  
  2760.     SYNTAX
  2761.     #include <stdio.h>
  2762.     int fd = fileno(fp); /* MACRO */
  2763.     FILE *fp;
  2764.  
  2765.     DESCRIPTION
  2766.     The fileno macro returns the file descriptor (open, close, read,
  2767.     write) associated with the file pointer (fopen, fclose, fread,
  2768.     fwrite). This is still not the AmigaDOS file handle; to get that you
  2769.     must use the fdtofh call.
  2770.  
  2771.     ## WARNING: If you use the file descriptor of a file pointer the file
  2772.     ## pointer will get its seek position confused. Additionally, there
  2773.     ## might be unflushed data in the file pointer's buffers that has not
  2774.     ## been written out to the file descriptor yet.  There also might be
  2775.     ## unread input on the file pointer's input buffers already read from
  2776.     ## the file descriptor.
  2777.  
  2778.     || NOTE: Refer to the file_pointer manual page for general
  2779.     || information.
  2780.  
  2781.     INPUTS
  2782.     FILE *fp;        file pointer
  2783.  
  2784.     RESULTS
  2785.     int  fd;        associated file descriptor
  2786.  
  2787.     SEE ALSO
  2788.     fdopen, fopen, fclose, open, close
  2789.  
  2790. dice/file_pointer                                          dice/file_pointer
  2791.  
  2792.     FUNCTION
  2793.     STDIO file_pointer (ANSI)
  2794.  
  2795.     DESCRIPTION
  2796.     A file pointer is the basis for stdio, a standard file management
  2797.     package available across all versions of C.  If you stick to the
  2798.     standard functions, your program should work on any machine that can
  2799.      compile C.
  2800.  
  2801.     The specific Amiga implementation builds file pointers (type "FILE
  2802.     *") on top of file descriptors (type "int"; see the file_descriptor
  2803.     manual page).  File pointers have a layer of buffering (good if you
  2804.     use many small reads and writes), while file descriptors pass
  2805.     requests directly to AmigaDOS.    Note that a stdio file pointer is not
  2806.     a file descriptor nor is a AmigaDOS file handle.  You may call only
  2807.     stdio routines (fopen, fclose, fread, fwrite, etc.) with file
  2808.     pointers.
  2809.  
  2810.     Some C implementations flush stdout whenever stdin is read.  DICE
  2811.     does not do this.
  2812.  
  2813. dice/fopen                                                        dice/fopen
  2814.  
  2815.     FUNCTION
  2816.     open a file and create a file pointer (ANSI)
  2817.  
  2818.     SYNTAX
  2819.     #include <stdio.h>
  2820.     FILE *fp = fopen(filename, modes)
  2821.     char *filename;
  2822.     char *modes;
  2823.  
  2824.     DESCRIPTION
  2825.     fopen is the grand master of stdio:  it opens and possibly creates a
  2826.     file and returns a new file pointer for use by the program. The first
  2827.     argument is the file to open, the second is a string containing one
  2828.     or mode characters defined as follows:
  2829.  
  2830.     Mode : Usage
  2831.     =====+===============================================================
  2832.     r    : open for reading, the file must already exist
  2833.     -----+---------------------------------------------------------------
  2834.     w    : open for writing, the file is created if it does not exist,
  2835.          : truncated if it does
  2836.     -----+---------------------------------------------------------------
  2837.     a    : open for append, writes always append to the file.
  2838.     -----+---------------------------------------------------------------
  2839.     a    : the file starts out positioned at the end instead of at the
  2840.          : beginning.  This mode also creates the file but only if it
  2841.          : does not already exist.
  2842.     -----+---------------------------------------------------------------
  2843.     r+   : also allows writing to the file in addition to reading
  2844.     -----+---------------------------------------------------------------
  2845.     w+   : also allows reading from the file
  2846.     -----+---------------------------------------------------------------
  2847.     b    : open for binary read/write, else the file is assumed to
  2848.          : contain text (this is ignored by DICE since there is no
  2849.          : difference on the Amiga).
  2850.     -----+---------------------------------------------------------------
  2851.  
  2852.     All combinations except "rw" are allowed.  One uses "r+" or "w+"
  2853.     instead of "rw".  By the above description "r+" is used to update an
  2854.     existing file while "w+" is used to create a new file and then allow
  2855.     reads as well as writes to it. "wa" is equivalent to creating a new
  2856.     file and then appending to it. "r+a" is equivalent to appending to an
  2857.     already existing file. Other examples of valid modes combinations:
  2858.     "r+b", "w+b", "rb", "wb", "ab", "w", "r", "r+", "a", etc...
  2859.  
  2860.     || NOTE: Refer to the file_pointer manual page for general
  2861.     || information.
  2862.  
  2863.     INPUTS
  2864.     char *filename;     file name to open
  2865.  
  2866.     char *modes;        open modes string
  2867.  
  2868.     RESULTS
  2869.     FILE *fp;        new file pointer
  2870.  
  2871.     SEE ALSO
  2872.     fdopen, fclose, open, close
  2873.  
  2874.     EXAMPLE
  2875.     #include <stdio.h>
  2876.     main()
  2877.     {
  2878.     FILE    *fp;
  2879.     char *    filename = "t:XX";
  2880.     char *    why     = "I don't do windows\n";
  2881.  
  2882.         fp = fopen(filename, "wb");
  2883.         if( fp )
  2884.         {
  2885.         fwrite(why, 1, strlen(why), fp);
  2886.         fwrite(why, strlen(why), 1, fp);
  2887.         fclose( fp );
  2888.         } else
  2889.         printf("Can't open file %s\n", filename);
  2890.         return(0);
  2891.  
  2892.     }
  2893.  
  2894. dice/fputc,putc                                              dice/fputc,putc
  2895.  
  2896.     FUNCTION
  2897.     fputc: write a single character (ANSI)
  2898.     putc: write a single character (ANSI)
  2899.  
  2900.     SYNTAX
  2901.     #include <stdio.h>
  2902.     int c = fputc(c, fp);
  2903.     int c = putc(c, fp); /* MACRO */
  2904.     FILE *fp;
  2905.  
  2906.     DESCRIPTION
  2907.     fputc writes a single character to a file pointer.  If all goes well
  2908.     the character is returned, else EOF is returned. fputc is a function
  2909.     call while putc is a macro
  2910.  
  2911.     || NOTE: Refer to the file_pointer manual page for general
  2912.     || information.
  2913.  
  2914.     INPUTS
  2915.     int c;            character to write
  2916.  
  2917.     FILE *fp;        file pointer
  2918.  
  2919.     RESULTS
  2920.     int c;            character written (same as first argument) or EOF
  2921.                 if error.
  2922.  
  2923.     SEE ALSO
  2924.     getc, putc, fputc, fread, fwrite, puts, fputs, gets, fgets
  2925.  
  2926.     EXAMPLE
  2927.     /*
  2928.      *  copy stdin to stdout using fgetc/fputc. Normally one
  2929.      *  uses fread/fwrite, but I'll save that for the fread
  2930.      *  manual page. note that I output the initial message
  2931.      *  to stderr so it does not get stuck into stdout in
  2932.      *  case the user has redirected stdout.
  2933.      */
  2934.     #include <stdio.h>
  2935.     main()
  2936.     {
  2937.        int c;
  2938.        fputs("Type a couple of lines, then ^\\ (EOF)\n",
  2939.           stderr);
  2940.        while ((c = fgetc(stdin)) != EOF)
  2941.        {
  2942.           fputc(c, stdout);
  2943.        }
  2944.        return(0);
  2945.     }
  2946.  
  2947. dice/fputs,puts                                              dice/fputs,puts
  2948.  
  2949.     FUNCTION
  2950.     fputs: write a string to a file pointer (ANSI)
  2951.     puts: then write a string to stdout, appending newline (ANSI)
  2952.  
  2953.     SYNTAX
  2954.     #include <stdio.h>
  2955.     int error = fputs(s, fp);
  2956.     int error = puts(s);
  2957.     const char *s;
  2958.     FILE *fp;
  2959.  
  2960.     DESCRIPTION
  2961.     fputs writes a string to a file pointer all the way up to, but not
  2962.     including, the NULL.  puts does the same thing but to stdout, and
  2963.     puts additionally writes a newline out.
  2964.  
  2965.     || NOTE: Refer to the file_pointer manual page for general
  2966.     || information.
  2967.  
  2968.     It is common to get confused between fputs and puts. Remember that
  2969.     puts adds a newline to the output while fputs does not.  gets strips
  2970.     the newline from an input line while fgets does not.
  2971.  
  2972.     INPUTS
  2973.     char *s;        string to write
  2974.  
  2975.     FILE *fp;        file pointer
  2976.  
  2977.     RESULTS
  2978.     int error;        0 or positive if all went ok, else negative. Note
  2979.                 that unlike printf() routines the numberr of
  2980.                 chars written out is NOT returned.
  2981.  
  2982.     SEE ALSO
  2983.     getc, putc, fputc, fread, fwrite, gets, fgets
  2984.  
  2985.     EXAMPLE
  2986.     #include <stdio.h>
  2987.     main()
  2988.     {
  2989.         /* note newline */
  2990.         fputs("This is a test of fputs\n", stdout);
  2991.         puts("This is a test of puts"); /*  note lack of */
  2992.         puts("That's it!");
  2993.         return(0);
  2994.     }
  2995.  
  2996. dice/fseek                                                        dice/fseek
  2997.  
  2998.     FUNCTION
  2999.     seek within a file pointer (ANSI)
  3000.  
  3001.     SYNTAX
  3002.     #include <stdio.h>
  3003.     int error = fseek(fp, offset, how);
  3004.     FILE *fp;
  3005.     long offset;
  3006.     int how;
  3007.  
  3008.     DESCRIPTION
  3009.     fseek changes the current seek position within a file. Offset is
  3010.     interpreted according to the how argument:
  3011.  
  3012.          :   :
  3013.     =========+===+=====================================================
  3014.     SEEK_SET : 0 : skip to position relative to beginning of file
  3015.     ---------+---+-----------------------------------------------------
  3016.     SEEK_CUR : 1 : skip to position relative to current position in
  3017.          :   : file
  3018.     ---------+---+-----------------------------------------------------
  3019.     SEEK_END : 2 : skip to position relative to end of file.
  3020.     ---------+---+-----------------------------------------------------
  3021.  
  3022.     So, for example, one may seek to the beginning of a file by fseek(fp,
  3023.     0L, SEEK_SET);, to the end of the file by fseek(fp, 0L, SEEK_END);.
  3024.     Calling getc at this time would return an immediate EOF.  You can
  3025.     skip characters in a file with something like fseek(fp, 5L,
  3026.     SEEK_CUR); which skips 5 characters.  Note that when seeking relative
  3027.     to the end of the file, negative offsets are used.  For example, to
  3028.     seek to the very last character in the file you would use fseek(fp,
  3029.     -1L, SEEK_END); fseek returns 0 on success, a negative number on
  3030.     ERROR.    A common mistake is to expect fseek to return the new
  3031.     position  of the file but this is not what is returned.  Use ftell or
  3032.     fgetpos to determine the current offset into a file.
  3033.  
  3034.     || NOTE: Refer to the file_pointer manual page for general
  3035.     || information fseek flushes any buffered write data before seeking.
  3036.  
  3037.     INPUTS
  3038.     FILE *fp;        file pointer to seek
  3039.  
  3040.     long offset;        relative offset, depending on how
  3041.  
  3042.     int how;        0, 1, or 2 (absolute, relative, end- relative)
  3043.  
  3044.     RESULTS
  3045.     int error;        Error code from operation
  3046.  
  3047.     SEE ALSO
  3048.     ftell, fgetpos, fsetpos, rewind
  3049.  
  3050.     EXAMPLE
  3051.     see fopen for an example
  3052.  
  3053. dice/fread                                                        dice/fread
  3054.  
  3055.     FUNCTION
  3056.     read data from a file pointer (ANSI)
  3057.  
  3058.     SYNTAX
  3059.     #include <stdio.h>
  3060.     size_t robjs = fread(buf, objsize, nobjs, fp);
  3061.     void *buf; size_t objsize; size_t nobjs;
  3062.     FILE *fp;
  3063.  
  3064.     DESCRIPTION
  3065.     fread reads an arbitrary number of objects from a file pointer into
  3066.     the specified buffer and returns the actual number of objects read.
  3067.     If the return value robjs is not equal to nobjs then fread was unable
  3068.     to read the requested number of objects due to either a read error or
  3069.     an EOF condition.  If the file is already completely exhausted fread
  3070.     simply returns 0. Having two size arguments, an object size and a
  3071.     number of objects, simplifies the reading of structure arrays off
  3072.     disk.
  3073.  
  3074.     || NOTE: To use fread to read an arbitrary number of bytes one
  3075.     || normally uses the form: r = fread(buf, 1, n, fp); that is, n
  3076.     || objects of size 1.  fread will attempt to read objsize * nobjs
  3077.     || bytes into the specified buffer.
  3078.  
  3079.     INPUTS
  3080.     void   *buf;        buffer to load data into
  3081.  
  3082.     size_t objsize;     size of one object
  3083.  
  3084.     size_t nobjs;        number of objects to read
  3085.  
  3086.     FILE   *fp;        file pointer to read objects from
  3087.  
  3088.     RESULTS
  3089.     size_t robjs;        number of objects actually read or 0 if EOF or
  3090.                 ERROR.
  3091.  
  3092.     SEE ALSO
  3093.     fwrite, fopen, fclose, fseek, ftell, rewind
  3094.  
  3095.     EXAMPLE
  3096.     #include stdlib.h
  3097.     #include stdio.h
  3098.  
  3099.     #define NOBJS    15
  3100.  
  3101.     typedef struct
  3102.         {
  3103.            short   a, b, c, d;
  3104.         }
  3105.         MyObj;
  3106.  
  3107.  
  3108.         main()
  3109.         {
  3110.            FILE *fp;
  3111.            MyObj O;
  3112.            if (fp = fopen("T:fwrite_tmp", "r"))
  3113.            {
  3114.               short n;
  3115.               for (n = 0; n < NOBJS; ++n)
  3116.               {
  3117.              O.a = n;
  3118.              O.b = n * 2;
  3119.              O.c = n * 3;
  3120.              O.d = n * 4;
  3121.              if (fread(&O, sizeof(MyObj), 1, fp) != 1)
  3122.              {
  3123.                 printf("read error, eof is %d\n",feof(fp));
  3124.                 exit(1);
  3125.              }
  3126.              else {
  3127.                 printf("read something, O.a is %d\n",O.a);
  3128.              }
  3129.               }
  3130.            fclose(fp);
  3131.            }
  3132.            return(0);
  3133.         }
  3134.  
  3135. dice/free                                                          dice/free
  3136.  
  3137.     FUNCTION
  3138.     free memory allocated by calloc, malloc, or strdup (ANSI)
  3139.  
  3140.     SYNTAX
  3141.     #include <stdlib.h>
  3142.     void free(ptr);
  3143.     void *ptr;
  3144.  
  3145.     DESCRIPTION
  3146.     free frees memory allocated by calloc, malloc, or strdup.
  3147.  
  3148.     || NOTE: Under ANSI C, it is legal to free(NULL). This is, however, a
  3149.     || bad idea to depend on.  Usually a free of the NULL pointer
  3150.     || indicates a bug in the code.
  3151.  
  3152.     INPUTS
  3153.     void *ptr;        pointer to memory to free
  3154.  
  3155.     SEE ALSO
  3156.     malloc, calloc, strdup
  3157.  
  3158.     EXAMPLE
  3159.     see calloc example
  3160.  
  3161. dice/freopen                                                    dice/freopen
  3162.  
  3163.     FUNCTION
  3164.     reopen a new file using an existing file pointer, the existing file
  3165.     is closed before it is reused (ANSI)
  3166.  
  3167.     SYNTAX
  3168.     #include <stdio.h>
  3169.     FILE *fp = freopen(filename, modes, ofp)
  3170.     char *filename;
  3171.     char *modes;
  3172.     FILE *ofp;
  3173.  
  3174.     DESCRIPTION
  3175.     freopen works exactly like fopen but takes an additional argument,  a
  3176.     file pointer to reuse. This file pointer, ofp, must reference a valid
  3177.     open file.  freopen will close out ofp then reuse the descriptor to
  3178.     open the new file, returning ofp (fp == ofp) on success, NULL on
  3179.     failure. If the freopen fails NULL is returned and the original file
  3180.     pointer is still closed, but not freed so you may call freopen again
  3181.     with the same ofp, even though it has already been closed.  Refer to
  3182.     the fopen manual page for information on the modes string. freopen is
  3183.     often used to change a program's stdin, stdout, or stderr though to
  3184.     be frank, using a separate file pointer is normally much more
  3185.     modular.
  3186.  
  3187.     ## WARNING: ANSI does not specify that the ofp can be used in a
  3188.     ## second freopen if the first freopen using ofp fails (returns
  3189.     ## NULL). Many implementations free the file pointer. This just might
  3190.     ## be the proper way of doing things but we don't know.  We suggest
  3191.     ## you do not use DICE's feature in that respect as we might have to
  3192.     ## change it back to free ofp if the new file is unopenable.
  3193.  
  3194.     || NOTE: Refer to the file_pointer manual page for general
  3195.     || information
  3196.  
  3197.     INPUTS
  3198.     char *filename;     file name to open
  3199.  
  3200.     char*modes;        open modes string
  3201.  
  3202.     FILE *ofp;        open file pointer to reuse
  3203.  
  3204.     RESULTS
  3205.     FILE *fp;        same as ofp if the new open worked, NULL
  3206.                 otherwise
  3207.  
  3208.     SEE ALSO
  3209.     fdopen, fopen, fclose, open, close
  3210.  
  3211.     EXAMPLE
  3212.     /*
  3213.      *  re-open stdin to an Amiga console device
  3214.      */
  3215.     #include <stdio.h>
  3216.     #include <assert.h>
  3217.     main()
  3218.     {
  3219.        char buf[256];
  3220.        assert(freopen("CON:0/0/320/100/freopen-in", "r",
  3221.           stdin));
  3222.        assert(freopen("CON:320/0/320/100/freopen-out", "w",
  3223.           stdout));
  3224.        /*
  3225.         *  set to line buffered
  3226.         */
  3227.        setvbuf(stdin, NULL, _IOLBF, 0);
  3228.        setvbuf(stdout, NULL, _IOLBF, 0);
  3229.        puts("Type a (short) line in the second window");
  3230.        gets(buf);
  3231.        fclose(stdin);
  3232.        fclose(stdout);
  3233.        fprintf(stderr, "Your line was: %s\n", buf);
  3234.        return(0);
  3235.     }
  3236.  
  3237. dice/fsetpos                                                    dice/fsetpos
  3238.  
  3239.     FUNCTION
  3240.     set position within file pointer (nearly equivalent to fseek
  3241.     absolute) (ANSI)
  3242.  
  3243.     SYNTAX
  3244.     #include <stdio.h>
  3245.     int error = fsetpos(fp, &pos);
  3246.     FILE *fp; fpos_t pos;
  3247.  
  3248.     DESCRIPTION
  3249.     fsetpos is a nearly useless call that is essentially the same as
  3250.     fseek(fp, (long)pos, 0); fsetpos seeks within a file pointer to the
  3251.     absolute position specified by an fpos_t type.    The address of an
  3252.     fpos_t object is passed to fsetpos. Normally one saves the current
  3253.     seek position into an fpos_t type using the fgetpos function, then
  3254.     seeks back using the fsetpos function.    In this way the programmer
  3255.     need not make any direct reference to the contents of the fpos_t
  3256.     type.
  3257.  
  3258.     INPUTS
  3259.     FILE *fp;        file pointer to seek
  3260.  
  3261.     fpos_t *pos;        pointer to fpos_t type previously initialized by
  3262.                 a fgetpos() call.
  3263.  
  3264.     RESULTS
  3265.     int error;        0 if no error, < 0 if error
  3266.  
  3267.     SEE ALSO
  3268.     ftell, fsetpos, fseek, rewind
  3269.  
  3270.     EXAMPLE
  3271.     /*
  3272.      *  get a line, save current position, get rest of
  3273.      *  file, go back to saved position, retrieve line
  3274.      *  again and print again.
  3275.      */
  3276.     #include <stdio.h>
  3277.     main(int ac, char*av[])
  3278.     {
  3279.        FILE *fp;
  3280.        fpos_t save_pos;
  3281.        int count;
  3282.        char buf[256];
  3283.        if (ac == 1)
  3284.        {
  3285.           puts("Expected textfile argument");
  3286.           exit(1);
  3287.        }
  3288.        fp = fopen(av[1], "r");
  3289.        if (fp == NULL)
  3290.        {
  3291.           printf("Unable to open %s\n", av[1]);
  3292.           exit(1);
  3293.        }
  3294.        for    (count = 0; fgets(buf, sizeof(buf), fp);
  3295.               ++count)
  3296.        {
  3297.           if (count == 0) /*  just before second line */
  3298.          fgetpos(fp, &save_pos);
  3299.           fprintf(stdout, "%-3d: %s", count + 1, buf);
  3300.        }
  3301.        if (count < 2)
  3302.        {
  3303.           puts("not enough lines in file for example!");
  3304.           exit(1);
  3305.        }
  3306.        puts("--end of file, now seeking back to line 2--");
  3307.        fsetpos(fp, &save_pos);
  3308.        if (fgets(buf, sizeof(buf), fp) == NULL)
  3309.        {
  3310.           puts("error!");
  3311.           exit(1);
  3312.        }
  3313.        fprintf(stdout, "%-3d: %s", 2, buf);
  3314.        fclose(fp);
  3315.        return(0);
  3316.     }
  3317.  
  3318. dice/fstat                                                        dice/fstat
  3319.  
  3320.     FUNCTION
  3321.     stat a file descriptor (UNIX)
  3322.  
  3323.     SYNTAX
  3324.     #include <sys/stat.h>
  3325.     int error = fstat(fd, &stat_buf);
  3326.     struct stat stat_buf;
  3327.  
  3328.     DESCRIPTION
  3329.     fstat is a UNIX-compatible call that returns information pertaining
  3330.     to the file represented by an open file descriptor. See stat for
  3331.     information on the struct stat fields.
  3332.  
  3333.     || NOTE: fstat works just like stat except you provide a UNIX file
  3334.     ||  descriptor (not an AmigaDOS File Handle).
  3335.     || Under 2.0, ExamineFH is used.  Under 1.3, the original path used
  3336.     || to open the file will be stat'd, which ends up scanning the
  3337.     || directory if the file was open for exclusive access.
  3338.  
  3339.     INPUTS
  3340.     int  fd;        file descriptor to stat
  3341.  
  3342.     struct stat *sbuf;
  3343.                 address of stat structure that will be filled in
  3344.  
  3345.     RESULTS
  3346.     int error;        0 on success, < 0 on error
  3347.  
  3348.     SEE ALSO
  3349.     chdir
  3350.  
  3351.     EXAMPLE
  3352.     #include <stdio.h>
  3353.     #include <fcntl.h>
  3354.     #include <sys/stat.h>
  3355.     main(int ac, char**av)
  3356.     {
  3357.        int r, fd;
  3358.        struct stat stat_buf;
  3359.        if (ac == 1)
  3360.        {
  3361.           puts("Expected a file name");
  3362.           exit(1);
  3363.        }
  3364.        fd = open(av[1], O_RDONLY );
  3365.        if( fd )
  3366.        {
  3367.           r = fstat(fd, &stat_buf);
  3368.           if (r < 0)
  3369.           printf("Can't stat fd=%d\n", fd);
  3370.           else
  3371.           {
  3372.         printf("File is %d bytes\n", stat_buf.st_size);
  3373.         printf("modified %s", ctime(&stat_buf.st_ctime));
  3374.           }
  3375.           close(fd);
  3376.        }
  3377.        return(0);
  3378.     }
  3379.  
  3380. dice/ftell                                                        dice/ftell
  3381.  
  3382.     FUNCTION
  3383.     return current position within file pointer (ANSI)
  3384.  
  3385.     SYNTAX
  3386.     #include <stdio.h>
  3387.     long pos = ftell(fp);
  3388.     FILE *fp;
  3389.  
  3390.     DESCRIPTION
  3391.     ftell returns the current absolute seek offset within a file pointer.
  3392.  
  3393.     INPUTS
  3394.     FILE *fp;        file pointer retrieve seek position from
  3395.  
  3396.     RESULTS
  3397.     long pos;        current absolute seek position in file
  3398.  
  3399.     SEE ALSO
  3400.     ftell, fgetpos, fsetpos, fseek, rewind
  3401.  
  3402.     EXAMPLE
  3403.     /*
  3404.      * get a line, save current position, get rest of file,
  3405.      * go backto saved position, retrieve line again and
  3406.      * print again.
  3407.      * like fsetpos() example but uses ftell()/fseek()
  3408.      * instead
  3409.      */
  3410.     #include <stdio.h>
  3411.     main(int ac, char**av)
  3412.     {
  3413.        FILE *fp;
  3414.        long save_pos;
  3415.        int count;
  3416.        char buf[256];
  3417.        if (ac == 1)
  3418.        {
  3419.           puts("Expected textfile argument");
  3420.           exit(1);
  3421.        }
  3422.        fp = fopen(av[1], "r");
  3423.        if (fp == NULL)
  3424.        {
  3425.           printf("Unable to open %s\n", av[1]);
  3426.           exit(1);
  3427.        }
  3428.        for (count = 0; fgets(buf, sizeof(buf), fp); ++count)
  3429.        {
  3430.           if (count == 0)      /*  just before second line */
  3431.          save_pos = ftell(fp);
  3432.           fprintf(stdout, "%-3d: %s", count + 1, buf);
  3433.        }
  3434.        if (count < 2)
  3435.        {
  3436.           puts("not enough lines in file for example!");
  3437.           exit(1);
  3438.        }
  3439.        puts("--end of file, now seeking back to line 2--");
  3440.        fseek(fp, save_pos, SEEK_SET);
  3441.        if (fgets(buf, sizeof(buf), fp) == NULL)
  3442.        {
  3443.           puts("error!");
  3444.           exit(1);
  3445.        }
  3446.        fprintf(stdout, "%-3d: %s", 2, buf);
  3447.        fclose(fp);
  3448.        return(0);
  3449.     }
  3450.  
  3451. dice/fwrite                                                      dice/fwrite
  3452.  
  3453.     FUNCTION
  3454.     write data to a file pointer (ANSI)
  3455.  
  3456.     SYNTAX
  3457.     #include <stdio.h>
  3458.     size_t robjs = fwrite(buf, objsize, nobjs, fp);
  3459.     const void *buf;
  3460.     size_t objsize;
  3461.     size_t nobjs;
  3462.     FILE *fp;
  3463.  
  3464.     DESCRIPTION
  3465.     fwrite writes the specified number of objects to a file pointer from
  3466.     the specified buffer and returns the actual number of objects written
  3467.     or 0 or -1 depending on the error.  If the return value robjs is not
  3468.     equal to nobjs then a write error occurred. Having two size
  3469.     arguments, an object size and number of objects, simplifies the
  3470.     reading of structure arrays off disk.
  3471.  
  3472.     || NOTE: To use fwrite to read an arbitrary number of bytes one
  3473.     || normally uses the form "r = fwrite(buf, 1, n, fp);", that is, n
  3474.     || objects of size 1.
  3475.  
  3476.     INPUTS
  3477.     void *buf;        buffer to copy data from
  3478.  
  3479.     size_t objsize;     size of one object
  3480.  
  3481.     size_t nobjs;        number of objects to write
  3482.  
  3483.     FILE *fp;        file pointer to read objects from
  3484.  
  3485.     RESULTS
  3486.     size_t robjs;        number of objects actually written (0 or EOF on
  3487.                 error)
  3488.  
  3489.     SEE ALSO
  3490.     fread, fopen, fclose, fseek, ftell, rewind
  3491.  
  3492. dice/getchar                                                    dice/getchar
  3493.  
  3494.     FUNCTION
  3495.     get character from stdin (ANSI)
  3496.  
  3497.     SYNTAX
  3498.     #include <stdio.h>
  3499.     int c = getchar(); /* MACRO */
  3500.  
  3501.     DESCRIPTION
  3502.     getchar returns the next available character on stdin or EOF if no
  3503.     more characters are available. getchar is equivalent to getc(stdin).
  3504.  
  3505.     || NOTE: Refer to the file_pointer manual page for general
  3506.     || information.
  3507.  
  3508.     INPUTS
  3509.     none
  3510.  
  3511.     RESULTS
  3512.     int c;            character 0 to 255, or EOF (-1) returned from
  3513.                 stdin
  3514.  
  3515.     SEE ALSO
  3516.     putc, putchar, fputc, fread, fwrite, getc
  3517.  
  3518.     EXAMPLE
  3519.     /*
  3520.      *  copy stdin to stdout using getchar/putchar. Normally
  3521.      *  one uses fread/fwrite, but I'll save that for the
  3522.      *  fread manual page.
  3523.      *  Note that I output the initial message to stderr
  3524.      *  so it does not get stuck into stdout in case the
  3525.      *  user has redirected stdout.
  3526.      *
  3527.      *  See getc manual page for equivalent example using
  3528.      *  getc/putc
  3529.      */
  3530.     #include <stdio.h>
  3531.     main()
  3532.     {
  3533.        int c;
  3534.        fputs("Type a couple of lines, then ^\\ (EOF)\n",
  3535.           stderr);
  3536.        while ((c = getchar()) != EOF)
  3537.        {
  3538.            putchar(c);
  3539.        }
  3540.        return(0);
  3541.     }
  3542.  
  3543. dice/getcwd                                                      dice/getcwd
  3544.  
  3545.     FUNCTION
  3546.     get current working directory (UNIX)
  3547.  
  3548.     SYNTAX
  3549.     #include <stdio.h>
  3550.     char *path = getcwd(buf, max);
  3551.     non-standard call
  3552.  
  3553.     DESCRIPTION
  3554.     getcwd gets the current working directory and puts it into the
  3555.     specified buffer buf. If buf is NULL it will be malloc'd
  3556.     automatically. The parameter buf is returned (or the malloc'd buffer
  3557.     if you passed NULL for buf). The parameter max specifies the maximum
  3558.     length of the path including the terminating NULL character. NULL is
  3559.     returned if any error occurs (such as malloc failing)
  3560.  
  3561.     INPUTS
  3562.     char *buf;        buffer to place current directory path into or
  3563.                 NULL if you want getcwd to allocate one
  3564.  
  3565.     int max;        maximum size of buffer
  3566.  
  3567.     RESULTS
  3568.     char *path;        returns allocated buffer if you passed NULL for
  3569.                 buf, else returns the first argument.  Returns
  3570.                 NULL on error.
  3571.  
  3572.     SEE ALSO
  3573.     chdir
  3574.  
  3575.     EXAMPLE
  3576.     #include <stdio.h>
  3577.     char buf[512];
  3578.     main(int ac, char**av)
  3579.     {
  3580.        getcwd(buf, sizeof(buf));
  3581.        printf("Current directory is: %s\n", buf);
  3582.        return(0);
  3583.     }
  3584.  
  3585. dice/GetDiceRexxPortSlot                            dice/GetDiceRexxPortSlot
  3586.  
  3587.     FUNCTION
  3588.     Determine an Application ARexx slot (DICE)
  3589.  
  3590.     SYNTAX
  3591.     #include <lib/rexx.h>
  3592.     slot = GetDiceRexxPortSlot(port, &nameptr);
  3593.     int slot;
  3594.     MsgPort *port;
  3595.     char *nameptr;
  3596.  
  3597.     DESCRIPTION
  3598.     GetDiceRexxPortSlot returns the ln_Name field of the specified port
  3599.     (i.e. the fully qualified port name) and extracts and returns the
  3600.     slot number.  -1 is returned if the port name does not terminate with
  3601.     ".xx" where xx is a number.  If a char ** pointer is passed as
  3602.     nameptr it will be initialized to point to the ln_Name field of the
  3603.     port.
  3604.  
  3605.     This call is normally used with port = NULL to obtain information
  3606.     about DICE's internally setup Rexx port.
  3607.  
  3608.     INPUTS
  3609.     struct MsgPort *port;
  3610.                 message port structure to extract ln_Name and
  3611.                 slot field from. You can pass NULL to extract the
  3612.                 full name and slot number selected by DICE when
  3613.                 automatic startup is used (i.e. your declaration
  3614.                 of RexxHostName is assigned a non-NULL pointer).
  3615.  
  3616.     char **nameptr;     The port name or NULL.  If not NULL the pointer
  3617.                 will be assigned the ln_Name field of the port.
  3618.                 Normally used when port is passed as NULL to
  3619.                 obtain the fully qualified rexx port name DICE
  3620.                 has constructed for you in an automatic startup.
  3621.  
  3622.     RESULTS
  3623.     int slot;        the slot number extracted from the port name or
  3624.                 -1 if the port name is not in the proper format.
  3625.  
  3626.     SEE ALSO
  3627.     CreateGlobalDiceRexxPort, CreateDiceRexxPort, DeleteDiceRexxPort
  3628.  
  3629.     EXAMPLE
  3630.     See DICE ARexx Support in chapter
  3631.  
  3632. dice/getenv                                                      dice/getenv
  3633.  
  3634.     FUNCTION
  3635.     get environment variable (ANSI)
  3636.  
  3637.     SYNTAX
  3638.     #include <stdlib.h>
  3639.     char *var = getenv(const char *name);
  3640.  
  3641.     DESCRIPTION
  3642.     getenv searches for and returns the ENV: environment variable
  3643.     requested.  getenv will cache variables so that requesting the same
  3644.     variable repeatedly does not allocate a new memory buffer.  getenv
  3645.     allocates a buffer for each variable returned, so you do not have to
  3646.     copy the return value from getenv.  This memory is free'd on program
  3647.     exit.  Do not attempt to free a getenv'd variable!!
  3648.  
  3649.     INPUTS
  3650.     char *name;        Name of environment variable, on the Amiga this
  3651.                 is not case sensitive. On UNIX systems it is.
  3652.  
  3653.     RESULTS
  3654.     char *var;        Contents of environment variable or NULL if the
  3655.                 variable could not be found.
  3656.  
  3657.     EXAMPLE
  3658.     #include <stdio.h>
  3659.     #include <stdlib.h>
  3660.     main(int ac, char**av)
  3661.     {
  3662.        char *dccopts = getenv("DCCOPTS");
  3663.        if (dccopts)
  3664.           printf("DCCOPTS = %s\n", dccopts);
  3665.        else
  3666.           printf("You do not have a DCCOPTS environment\
  3667.               variable!\n");
  3668.        return(0);
  3669.     }
  3670.  
  3671. dice/getfnl                                                      dice/getfnl
  3672.  
  3673.     FUNCTION
  3674.     get file name list: scan directory, return list of files that match
  3675.     the optional wildcard (DICE)
  3676.  
  3677.     SYNTAX
  3678.     #include <stdlib.h>
  3679.     int n = getfnl(pat, buf, bufsize, attr);
  3680.  
  3681.     const char *pat;
  3682.     char *buf;
  3683.     int bufsize;
  3684.     int attr;
  3685.  
  3686.     DESCRIPTION
  3687.     getfnl scans the specified anchored AmigaDOS pattern and fills the
  3688.     specified buffer (up to bufsize bytes) with file names separated by a
  3689.     NULL character (\0), ending the list with a double NULL (\0\0).
  3690.     getfnl returns the number of files/dirs in the buffer or -1 if there
  3691.     is not enough room  The pattern pat is an AmigaDOS pattern such as
  3692.     "df0:#?.c". The parameter buf is a buffer of bufsize bytes.  The
  3693.     parameter attr determines what kinds of files are valid:    0 for
  3694.     normal files only, 1 for files and directories
  3695.  
  3696.     || NOTE: getfnl exists for compatibility only;    expand_args is a much
  3697.     || better function function to use if you want a list of files &
  3698.     || dirs.
  3699.  
  3700.     INPUTS
  3701.     const char *pat;    pattern to scan for (anchored)
  3702.  
  3703.     char *buf;        buffer to put results in
  3704.  
  3705.     int bufsize;        size of buffer
  3706.  
  3707.     int attr;        attribes (0 or 1)
  3708.  
  3709.     RESULTS
  3710.     int n;            number of file names in buffer or -1 on error
  3711.  
  3712.     SEE ALSO
  3713.     strbpl, expand_args
  3714.  
  3715.     EXAMPLE
  3716.     #include <stdio.h>
  3717.     char Buf[4096];
  3718.     main(int ac, char**av)
  3719.     {
  3720.        int n;
  3721.        if (ac != 2)
  3722.        {
  3723.           puts("Expected an anchored wildcard such as '#?'");
  3724.           exit(1);
  3725.        }
  3726.        n = getfnl(av[1], Buf, sizeof(Buf), 1);
  3727.        {
  3728.           char *ptr = Buf;
  3729.           while (*ptr)
  3730.           {
  3731.           /*  look for \0\0   */
  3732.           puts(ptr);
  3733.           ptr += strlen(ptr) + 1;
  3734.           /*  skip first \0   */
  3735.           }
  3736.        }
  3737.        return(0);
  3738.     }
  3739.  
  3740. dice/GetHead,GetTail,GetSucc,GetPred    dice/GetHead,GetTail,GetSucc,GetPred
  3741.  
  3742.     FUNCTION
  3743.     Manipulate EXEC style lists (DICE)
  3744.  
  3745.     SYNTAX
  3746.     #include <lists.h>
  3747.     struct Node *node = GetHead(list);
  3748.     struct Node *node = GetTail(list);
  3749.     struct Node *node = GetSucc(oldNode);
  3750.     struct Node *node = GetPred(oldNode);
  3751.     const struct Node *oldNode;
  3752.     const struct List *list;
  3753.  
  3754.     DESCRIPTION
  3755.     These functions allow scanning of EXEC style lists (which are also
  3756.     useful for many programs having nothing to do with EXEC). GetHead
  3757.     returns the first node in a list or NULL if the list is empty;
  3758.     GetTail returns the last node in a list or NULL if the list is empty;
  3759.     GetSucc returns the next node in a list (given some intermediate
  3760.     node) or NULL when we reach the end of the list GetPred returns the
  3761.     previous node in a list before some intermediate node or NULL when we
  3762.     reach the beginning of the list
  3763.  
  3764.     || NOTE: These are DICE functions and do not exist outside of DICE,
  3765.     || though they could be easily written.
  3766.  
  3767.     INPUTS
  3768.     struct List *list;
  3769.                 list to get head or tail node from
  3770.  
  3771.     struct Node *oldNode;
  3772.                 node from which to get relative successor or
  3773.                 predecessor from
  3774.  
  3775.     RESULTS
  3776.     struct Node *node;
  3777.                 returned node or NULL
  3778.  
  3779.     EXAMPLE
  3780.     /*
  3781.      *  A simple symbol create/delete/list program.
  3782.      *  (Note: for a real symbol table you'd want
  3783.      *  to use hash tables)
  3784.      */
  3785.     #include <lists.h>  /* non-standard header file */
  3786.     #include <stdio.h>
  3787.     #include <stdlib.h>
  3788.     #include <string.h>
  3789.     typedef struct List List;
  3790.     typedef struct Node Node;
  3791.     List SymList;
  3792.     void AddSymbol(char *);
  3793.     void DelSymbol(char *);
  3794.     Node *FindSymbol(char *);
  3795.     main()
  3796.     {
  3797.        char buf[256];
  3798.        char symBuf[256];
  3799.        short notDone = 1;
  3800.        NewList(&SymList);
  3801.        puts("(return for help)");
  3802.        while (notDone)
  3803.        {
  3804.           printf("Enter Command: ");
  3805.           fflush(stdout);
  3806.           if ( fgets(buf, sizeof(buf), stdin) == NULL)
  3807.          break;
  3808.           switch(buf[0])
  3809.           {
  3810.          case 'a': if (sscanf(buf + 1,"%s",symBuf)== 1)
  3811.             AddSymbol(symBuf);
  3812.             break;
  3813.          case 'd': if (sscanf(buf + 1,"%s",symBuf)== 1)
  3814.             DelSymbol(symBuf);
  3815.             break;
  3816.          case 'l': { Node *node;
  3817.             for (node = GetHead(&SymList); node;
  3818.             node = GetSucc(node))
  3819.             puts(node->ln_Name);
  3820.           }
  3821.           break;
  3822.           case 'q': notDone = 0;
  3823.             break;
  3824.          default: puts("<return>      -help   ");
  3825.             puts("a name-add symbol");
  3826.             puts("d name-delete symbol");
  3827.             puts("l     -list symbols");
  3828.             puts("q     -quit");
  3829.             break;
  3830.        }
  3831.     }
  3832.     puts("bye!");
  3833.     return(0);
  3834.     }
  3835.  
  3836.     void AddSymbol(name)
  3837.     char *name;
  3838.     {
  3839.        Node *node;
  3840.        if (FindSymbol(name))
  3841.        {
  3842.           puts("already exists!");
  3843.           exit(1);
  3844.        }
  3845.        if (node = malloc(sizeof(Node)))
  3846.        {
  3847.           AddTail(&SymList, node);
  3848.           node->ln_Name = strdup(name);
  3849.           /* bad code, not checking */
  3850.           /* for error result!    */
  3851.        }
  3852.     }
  3853.  
  3854.     void DelSymbol(name)
  3855.     char *name;
  3856.     {
  3857.        Node *node;
  3858.        if (node = FindSymbol(name))
  3859.        {
  3860.           Remove(node);   /*  take out of list    */
  3861.           free(node->ln_Name);    /*  free name   */
  3862.           free(node);     /*  free node last      */
  3863.           puts("ok");
  3864.           }
  3865.        else
  3866.        {
  3867.           puts("Couldn't find it!");
  3868.        } }
  3869.  
  3870.     Node * FindSymbol(name)
  3871.     char *name;
  3872.     {
  3873.        Node *node;
  3874.        for (node = GetHead(&SymList); node;
  3875.          node = GetSucc(node))
  3876.        {
  3877.         if (strcmp(node->ln_Name, name) == 0)
  3878.         return(node);
  3879.        }
  3880.        return(NULL);
  3881.     }
  3882.  
  3883. dice/gets                                                          dice/gets
  3884.  
  3885.     FUNCTION
  3886.     get a line from stdin (ANSI)
  3887.  
  3888.     SYNTAX
  3889.     #include <stdio.h>
  3890.     char *ptr = gets(buf);
  3891.     char *buf;
  3892.  
  3893.     DESCRIPTION
  3894.     gets takes a line from stdin and places it into your buffer.  A null
  3895.     (\0) is placed in the buffer instead of the newline (\n).  While the
  3896.     function can be convenient, if your buffer is not large enough, you
  3897.     loose. See fgets for a more reasonable function.
  3898.  
  3899.  gets, puts
  3900.         These functions strip newline on input, add newline on output.
  3901.         gets works on stdin, puts on stdout.
  3902.  
  3903.  fgets, fputs
  3904.         These functions leave newlines alone on input, don't add to the
  3905.         output. Any file pointer, including stdin and stdout may be
  3906.         specified.
  3907.  
  3908.         || NOTE: Refer to the file_pointer manual page for general
  3909.         || information.
  3910.  
  3911.     INPUTS
  3912.     char *buf;        buffer, must be able to maximum possible line
  3913.  
  3914.     RESULTS
  3915.     char *ptr;        buf if all is well, or NULL if error or EOF
  3916.  
  3917.     SEE ALSO
  3918.     puts, fputs, fgets, fread, getc, fgetc
  3919.  
  3920.     EXAMPLE
  3921.     #include <stdio.h>
  3922.     main()
  3923.     {
  3924.        char buf[128];
  3925.        printf("Enter a line - ");
  3926.        fflush(stdout);
  3927.        if (gets(buf) == NULL) // Enter a long line to crash
  3928.           exit(1);
  3929.        printf("Your line was: %s\n", buf);
  3930.        return(0);
  3931.     }
  3932.  
  3933. dice/isalnum,isalpha,iscntrl,isdigit,isgraph,islower,isprint,ispunct,isspace,isupper,isxdigit
  3934.  
  3935.     FUNCTION
  3936.     Test a character for assorted attributes (ANSI)
  3937.  
  3938.     SYNTAX
  3939.     #include <ctype.h>
  3940.     int r = isxxxxx(c);
  3941.     int c;
  3942.  
  3943.     || NOTE: These are MACROS if you #include <ctype.h>, function calls
  3944.     || if you do not.
  3945.  
  3946.     DESCRIPTION
  3947.     These function return non-zero (true) if the test is true, and zero
  3948.     (false) if not.
  3949.  
  3950.     || NOTE: When a non-zero value is returned, this value might be
  3951.     || anything other than zero.  It is not necessarily a 1.  It is
  3952.     || guaranteed to fit in a short, however, and still remain
  3953.     ||  non-zero.
  3954.     ||
  3955.     || Characters in the -1 to 255 range are valid inputs. Characters
  3956.     || less than -1 or larger than 255 are illegal and the results will
  3957.     || be random.  If you are passing a CHAR, you must cast it to an
  3958.     || UNSIGNED CHAR first. EOF is a valid input, and always returns
  3959.     || false
  3960.  
  3961.    isalpha  Returns non-zero if the character is a letter in the alphabet
  3962.         (a-z, A-Z).
  3963.  
  3964.    isalnum  Returns non-zero if the character is alphanumeric (a-z, A-Z,
  3965.         0-9).
  3966.  
  3967.    iscntrl  Returns non-zero if the character is a control character (decimal
  3968.         0 to 31).
  3969.  
  3970.    isdigit  Returns non-zero if the character is a digit ('0' through '9').
  3971.  
  3972.    isgraph  Returns non-zero if the character is printable and not a space.
  3973.         isgraph is the same as isprint, but with the space character
  3974.         excluded from the printable set.
  3975.  
  3976.    islower  Returns non-zero if the character is a lower case letter 'a' -
  3977.         'z'.
  3978.  
  3979.     isprint
  3980.  
  3981.     Returns non-zero if the character is printable. isprint is the same
  3982.     as isgraph, but with the space character included in the printable
  3983.     set.
  3984.  
  3985.    ispunct  Returns non-zero if the character is any sort of punctuation,
  3986.         including punctuation in the extended ASCII range.    Basically, if
  3987.         it is not a control character, alpha or a digit, it is
  3988.         punctuation.
  3989.  
  3990.    isspace  Returns non-zero if the character is any sort of white space.
  3991.         Included are space, shifted space, line feed (lf), form feed
  3992.         (ff), carriage return (cr), tab, and vertical tab.
  3993.  
  3994.    isupper  Returns non-zero if the character is an upper case letter 'A'
  3995.         -'Z'.
  3996.  
  3997.   isxdigit  Returns non-zero if the character is a valid hexadecimal digit
  3998.         '0' - '9', 'a' - 'f', or 'A' - 'F'.
  3999.  
  4000.         These macros use a lookup table.  One table handles the eight
  4001.         most common functions.  A second table handles ispunct, isxdigit
  4002.         and isprint.  It saves space if you reference only one table.
  4003.         There is space in the second table if you wish to add your own
  4004.         tests (you'll have to recompile the library source code).
  4005.  
  4006.     INPUTS
  4007.     int c;            character that we are checking
  4008.  
  4009.     RESULTS
  4010.     int r;            0 if the check failed, non-zero if the check is
  4011.                 true
  4012.  
  4013.     SEE ALSO
  4014.     tolower, toupper
  4015.  
  4016.     #include <stdio.h>
  4017.     #include <ctype.h>
  4018.     main()
  4019.     {
  4020.     int c;
  4021.  
  4022.         for( c=0; c<256; c++) {
  4023.         if( (c & 31) == 0 )    /* 32 per line */
  4024.             printf("\n%02x: ", c);
  4025.         if( isprint( c ) )
  4026.             printf("%c", c );   /* character */
  4027.         else
  4028.             printf("%c", 127 ); /* placeholder */
  4029.         }
  4030.         printf("\n");
  4031.         for( c=0; c<256; c++) {
  4032.         if( (c & 31) == 0 )    /* 32 per line */
  4033.             printf("\n%02x: ", c);
  4034.         if( ispunct( c ) )
  4035.             printf("x");        /* true */
  4036.         else
  4037.             printf("-");        /* false */
  4038.         }
  4039.         printf("\n");
  4040.         return( 0 );
  4041.     }
  4042.  
  4043. dice/isatty                                                      dice/isatty
  4044.  
  4045.     FUNCTION
  4046.     Test if a a file descriptor is a TTY (UNIX)
  4047.  
  4048.     SYNTAX
  4049.     #include <ctype.h>
  4050.     int r = isatty(fd); int fd;
  4051.  
  4052.     DESCRIPTION
  4053.     isatty returns TRUE (1) if the file descriptor is associated with a
  4054.     console, FALSE (0) if not, or -1 if an error condition occurs (such
  4055.     as illegal file descriptor).
  4056.  
  4057.     || NOTE: The standard input (0), standard output (1), and standard
  4058.     || error (2) can all return different values for isatty depending on
  4059.     || how the program is redirected.  A program whose standard in and
  4060.     || standard out is redirected may still have a standard error that is
  4061.     || connected to the console. Refer to the file_descriptor manual page
  4062.     || for general information.  Unlike file pointers and file handles,
  4063.     || the file descriptor is checked for validity and will simply return
  4064.     || an error if illegal.
  4065.  
  4066.     INPUTS
  4067.     int fd;         file descriptor
  4068.  
  4069.     RESULTS
  4070.     int r;            result, 1 if a tty, 0 if not, or -1 if error
  4071.  
  4072.     SEE ALSO
  4073.     close, creat, fcntl, fdtofh, getfh, ioctl, lseek, mkdir, open, read,
  4074.     rmdir, unlink, write
  4075.  
  4076. dice/ioctl                                                        dice/ioctl
  4077.  
  4078.     FUNCTION
  4079.     IO control on file descriptor (UNIX)
  4080.  
  4081.     SYNTAX
  4082.     #include <fcntl.h>
  4083.     int r = ioctl(fd, req, parg1, parg2);
  4084.     int fd;
  4085.     int req;
  4086.     int *parg1;
  4087.     int *parg2;
  4088.  
  4089.     DESCRIPTION
  4090.     ioctl executes an IO control on the file descriptor.  Currently no IO
  4091.     controls are implemented.
  4092.  
  4093.     INPUTS
  4094.     int fd;         file descriptor
  4095.  
  4096.     int req;        request from <ioctl.h>
  4097.  
  4098.     int *parg1;        address of argument #1
  4099.  
  4100.     int *parg2;        address of argument #2
  4101.  
  4102.     RESULTS
  4103.     int r;            result, error if < 0.
  4104.  
  4105.     SEE ALSO
  4106.     close, creat, fcntl, fdtofh, getfh, isatty, lseek, mkdir, open, read,
  4107.     rmdir, unlink, write
  4108.  
  4109. dice/localtime                                                dice/localtime
  4110.  
  4111.     FUNCTION
  4112.     convert time into broken down time (ANSI)
  4113.  
  4114.     SYNTAX
  4115.     #include <time.h>
  4116.     struct tm *tp = localtime(&t);
  4117.     time_t t;
  4118.  
  4119.     DESCRIPTION
  4120.     localtime takes the address of a time_t variable and breaks up the
  4121.     time into component parts, storing them in a static tm structure.
  4122.     The address of this structure is returned.  Since the broken up time
  4123.     is stored into a static structure, the structure will get overwritten
  4124.     on the next call to localtime. The fields of the tm structure are:
  4125.  
  4126.     struct tm {
  4127.            int tm_sec;     /*  0-59    */
  4128.            int tm_min;     /*  0-59    */
  4129.            int tm_hour;    /*  0-23    */
  4130.            int tm_mday;    /*  1-31    */
  4131.            int tm_mon;     /*  0-11    */
  4132.            int tm_year;    /*  n+1900  */
  4133.            int tm_wday;    /*  (sun)0-6*/
  4134.            int tm_yday;    /*  0-366   */
  4135.            int tm_isdst;   /*  is daylight savings? */
  4136.     /* (DICE does not implement the is daylight flag) */
  4137.     };
  4138.  
  4139.     INPUTS
  4140.     time_t *t;        pointer to a time_t
  4141.  
  4142.     RESULTS
  4143.     struct tm *tp;        pointer to a struct tm structure filled out
  4144.                 according to the passed time.
  4145.  
  4146.     SEE ALSO
  4147.     time, asctime, strftime, ctime, clock
  4148.  
  4149.     EXAMPLE
  4150.     /*
  4151.      *  Note that it is much easier to format time/date
  4152.      *  strings with strftime().
  4153.      */
  4154.     #include <stdio.h>
  4155.     #include <time.h>
  4156.     main()
  4157.     {
  4158.        time_t t = time(NULL);
  4159.        struct tm *tp = localtime(&t);
  4160.        printf("The time is %02d:%02d:%02d\n", tp->tm_hour,
  4161.             tp->tm_min, tp->tm_sec);
  4162.        return(0);
  4163.     }
  4164.  
  4165. dice/LockAddr,LockAddrB,TryLockAddr,TryLockAddrB,UnlockAddr,UnlockAddrB
  4166.  
  4167.     FUNCTION
  4168.     LockAddr: Gain Exclusive, Fast semaphore (bit 0)
  4169.     LockAddrB: Gain Exclusive, Fast semaphore (bit n 0-7)
  4170.     TryLockAddr: Non- Blocking version of LockAddr
  4171.     TryLockAddrB: Non-Blocking version of LockAddrB
  4172.     UnlockAddr: Release exclusive semaphore, bit 0
  4173.     UnlockAddrB: Release exclusive semaphore, bit n 0-7 (DICE)
  4174.  
  4175.     SYNTAX
  4176.     void LockAddr(lck);
  4177.     void LockAddrB(bitno, lck);
  4178.     int r = TryLockAddr(lck);
  4179.     int r = TryLockAddrB(bitno, lck);
  4180.     void UnlockAddr(lck);
  4181.     void UnlockAddrB(bitno, lck);
  4182.     long lck[2];
  4183.  
  4184.     DESCRIPTION
  4185.     These are custom DICE functions used for inter-task locking
  4186.     semaphores in programs that need such functions.  These routines are
  4187.     somewhat faster than standard Amiga semaphore routines and take less
  4188.     memory, though at the cost of DICE specific. To use an inter-task
  4189.     lock one first initializes an lck array to 0's. The entry long
  4190.     lck[2]; is an array of two longwords that the lock routines will use
  4191.     to do their stuff.  This array should be zero'd only once at program
  4192.     initialization time (the master task before any other tasks are
  4193.     created that use it). Each lck array may hold up to 8 locks, hence
  4194.     the LockAddrB calls. The non-B calls use lock #0 for simplicity.  For
  4195.      simplicity we will only discuss non-B calls.
  4196.     To gain a lock you may call LockAddr with the address of the lck
  4197.     array (which, being an array, does not need the & in the call). This
  4198.     routine will not return until the lock can be obtained. You may also
  4199.     use TryLockAddr to attempt to gain a lock. The return value is:    -1
  4200.     if the command is unable to obtain the lock (that is, it is in use),
  4201.     1 if the lock has been obtained.  To release an obtained lock you
  4202.     call UnlockAddr(lck).
  4203.  
  4204.     ## WARNING: DO NOT RELEASE A LOCK YOU DO NOT HAVE!
  4205.  
  4206.     INPUTS
  4207.     long *lck;        a pointer to two longwords, initially zero'd
  4208.  
  4209.     -int bitno;        lock # ... up to 8 independent locks exist for
  4210.                 each lck structure
  4211.  
  4212.     RESULTS
  4213.     int r;            (TryLock only), -1 on failure, 1 on success.
  4214.  
  4215.     EXAMPLE
  4216.     /*
  4217.      *  This program obtains a lock based at a public
  4218.      *  message port and holds it for ten seconds before
  4219.      *  releasing it. The public message port is left
  4220.      *  in memory (but only exists once no matter how
  4221.      *  many programs you run).
  4222.      *
  4223.      *  To test locking, open up two or more CLI's and run
  4224.      *  the program simultaneously (or as close as your
  4225.      *  fingers can make it) two or more times.  Only one
  4226.      *  program will 'have' the lock at a time.
  4227.      *
  4228.      *  we use AllocMem() so the port survives the program
  4229.      */
  4230.  
  4231.     #include <exec/types.h>
  4232.     #include <exec/ports.h>
  4233.     #include <exec/memory.h>
  4234.     #include <stdio.h>
  4235.     #include <stdlib.h>
  4236.     #include <assert.h>
  4237.  
  4238.     typedef struct
  4239.     {
  4240.        struct MsgPort Port;
  4241.        long   Lock[2];
  4242.     }
  4243.     MyPort;
  4244.  
  4245.     extern void *FindPort();
  4246.     extern void *CreatePort();
  4247.     extern void *AllocMem();
  4248.     MyPort *Port;
  4249.     short HaveLock;
  4250.  
  4251.     int brk()
  4252.     {
  4253.        if (HaveLock)
  4254.        UnlockAddr(Port->Lock);
  4255.        return(1);       /*  abort   */
  4256.     }
  4257.  
  4258.     main()
  4259.     {
  4260.        char *portName = "Lock-Test";
  4261.        onbreak(brk);
  4262.        Forbid();
  4263.        if ((Port = FindPort(portName)) == NULL)
  4264.        {
  4265.           MyPort *port;
  4266.           port = AllocMem(sizeof(MyPort) + strlen(portName)
  4267.                   + 1, MEMF_PUBLIC | MEMF_CLEAR);
  4268.                   assert(port);
  4269.           port->Port.mp_Node.ln_Name = (char *)(port + 1);
  4270.           port->Port.mp_Node.ln_Type = NT_MSGPORT;
  4271.           strcpy(port->Port.mp_Node.ln_Name, portName);
  4272.           AddPort(port);
  4273.           Port = port;
  4274.        }
  4275.        Permit();
  4276.        puts("getting lock");
  4277.        LockAddr(Port->Lock);
  4278.        HaveLock = 1;
  4279.        puts("Got the lock!, sleeping for 10 seconds");
  4280.        sleep(10);
  4281.        UnlockAddr(Port->Lock);
  4282.        HaveLock = 0;
  4283.        puts("released lock");
  4284.        return(0);
  4285.     }
  4286.  
  4287. dice/log,flog                                                  dice/log,flog
  4288.  
  4289.     FUNCTION
  4290.     log: return the log of a double, base e (ANSI)
  4291.     flog: return the log a float, base e (ANSI)
  4292.  
  4293.     LIBRARY
  4294.     m.lib
  4295.  
  4296.     SYNTAX
  4297.     #include <math.h>
  4298.     double a = log(b);
  4299.     double b;
  4300.     float  c = flog(d);
  4301.     float  d;
  4302.  
  4303.     DESCRIPTION
  4304.     The former command returns the log of the double quantity, base e;
  4305.     the latter returns the log of the float quantity, base e.
  4306.  
  4307.     INPUTS
  4308.     double b;        double floating point value float d; float
  4309.                 floating point value
  4310.  
  4311.     RESULTS
  4312.     double a;        result double floating point value float c;
  4313.                 result float  floating point value
  4314.  
  4315.     SEE ALSO
  4316.     acos, asin, atan, cos, exp, fabs, log10, pow, sin, sqrt, tan facos,
  4317.     fasin
  4318.  
  4319. dice/log10,flog10                                          dice/log10,flog10
  4320.  
  4321.     FUNCTION
  4322.     log10: return the logarithm of a double, base 10 (ANSI)
  4323.     flog10: return the logarithm of a float, base 10 (ANSI)
  4324.  
  4325.     LIBRARY
  4326.     m.lib
  4327.  
  4328.     SYNTAX
  4329.     #include <math.h>
  4330.     double a = log10(b);
  4331.     double b;
  4332.     float  c = flog10(d);
  4333.     float  d;
  4334.  
  4335.     DESCRIPTION
  4336.     log10 returns the log of a double quantity, base 10; flog10 returns
  4337.     the log of the floating point quantity, base 10.
  4338.  
  4339.     INPUTS
  4340.     double b;        double floating point value
  4341.  
  4342.     float d;        float floating point value
  4343.  
  4344.     RESULTS
  4345.     double a;        result double floating point value
  4346.  
  4347.     float c;        result float  floating point value
  4348.  
  4349.     SEE ALSO
  4350.     acos, asin, atan, cos, exp, fabs, log, pow, sin, sqrt, tan facos,
  4351.     fasin
  4352.  
  4353.     EXAMPLE
  4354.     /*
  4355.      *  compile with the math library -lm
  4356.      */
  4357.     #include <math.h>
  4358.     #include <stdio.h>
  4359.     main()
  4360.     {
  4361.        {
  4362.           double a = log10(0.25);
  4363.           printf("log10 0.25 = %lf\n", a); /* -0.6021 */
  4364.        }
  4365.        {  /*  less accuracy   */
  4366.           float a = flog10(0.25);
  4367.           printf("log10 0.25 = %lf\n", (double)a);
  4368.        }
  4369.        return(0);
  4370.     }
  4371.  
  4372. dice/lseek                                                        dice/lseek
  4373.  
  4374.     FUNCTION
  4375.     seek within a file descriptor (UNIX)
  4376.  
  4377.     SYNTAX
  4378.     #include <fcntl.h>
  4379.     long newpos = lseek(fd, offset, how)
  4380.     int fd;
  4381.     long offset;
  4382.     int how;
  4383.  
  4384.     DESCRIPTION
  4385.     lseek changes where the file descriptor points to within the open
  4386.     file.  You may specify an offset relative to the  beginning of the
  4387.     file, the current position in the file, or the end of the file:
  4388.  
  4389.        Val : Purpose
  4390.        ====+=========================================================
  4391.        0   : absolute offset (relative to the beginning of the file)
  4392.        ----+---------------------------------------------------------
  4393.        1   : offset relative to the current position in the file
  4394.        ----+---------------------------------------------------------
  4395.        2   : offset relative to the end of the file
  4396.        ----+---------------------------------------------------------
  4397.  
  4398.     Negative offsets may be specified when relative modes are used. The
  4399.     function lseek returns the new position in the file relative to the
  4400.     beginning of the file (i.e. an absolute offset).
  4401.  
  4402.     || NOTE: offsets are relative.    So, for example, if you want to seek
  4403.     || to the fourth character from the end of the file you would
  4404.     || lseek(fd, -4L, 2);.    Refer to the file_descriptor manual page for
  4405.     || general information.  Unlike file pointers and file handles, the
  4406.     || file descriptor is checked for validity and will simply return an
  4407.     || error if illegal.
  4408.  
  4409.     INPUTS
  4410.     int fd;         file descriptor
  4411.  
  4412.     long offset;        offset relative to how
  4413.  
  4414.     int how;        0 = rel beginning, 1 = rel middle, 2 = rel end
  4415.  
  4416.     RESULTS
  4417.     int newpos;        new position in file (absolute) or < 0 if error
  4418.  
  4419.     SEE ALSO
  4420.     close, creat, fcntl, fdtofh, getfh, ioctl, isatty, mkdir, open, read,
  4421.     rmdir, unlink, write
  4422.  
  4423.     EXAMPLE
  4424.     See open for an example.
  4425.  
  4426. dice/main                                                          dice/main
  4427.  
  4428.     FUNCTION
  4429.     main program entry (ANSI)
  4430.  
  4431.     SYNTAX
  4432.     #include <anything.h>
  4433.     int main(int argc, char **argv)
  4434.     {
  4435.        /* your pride and joy goes here */
  4436.     }
  4437.  
  4438.     DESCRIPTION
  4439.     The main routine is the entry point called after normal
  4440.     initialization of c.lib and the program environment is done by the
  4441.     startup module (c.o) and _main routine (in c.lib).  Under ANSI C main
  4442.     is expected to return an integer exit code. You can no longer simply
  4443.     fall through without returning any value.  Returning an exit code
  4444.     from your main routine is exactly the same as exiting with it.
  4445.  
  4446.     || NOTE: Any program run from the WORKBENCH uses a different access
  4447.     || point. Specifically, a program run from the WORKBENCH will run
  4448.     || wbmain instead of main.  Please refer to the manual    page for
  4449.     || wbmain for WORKBENCH operation.
  4450.  
  4451.     If you do not supply a wbmain a dummy wbmain will be supplied by the
  4452.     library which simply exits out of the program.
  4453.  
  4454.     INPUTS
  4455.     int argc;        number of arguments
  4456.  
  4457.     char *argv;        array pointer to arguments
  4458.  
  4459.     SEE ALSO
  4460.     wbmain, _main, exit, _exit
  4461.  
  4462.     EXAMPLE
  4463.     /* Print back out all given arguments */
  4464.     #include <stdio.h>
  4465.  
  4466.     int main(int ac, char**av)
  4467.     {
  4468.        int i;
  4469.        for (i = 0; i < ac; ++i) {
  4470.           printf("Arg #%d = %s\n", i, av[i]);
  4471.        }
  4472.        return(0);
  4473.     }
  4474.  
  4475. dice/_main                                                        dice/_main
  4476.  
  4477.     FUNCTION
  4478.     main program entry, bypass standard c.lib initialization (DICE)
  4479.  
  4480.     SYNTAX
  4481.     #include <the_world.h>
  4482.     void _main(int arglen, char *argptr)
  4483.     {
  4484.         /* your very special code goes here */
  4485.     }
  4486.  
  4487.     DESCRIPTION
  4488.     The _main entry point is called by the startup module (c.o).
  4489.     Normally _main is part of c.lib and does stdio and other
  4490.     initialization before calling the user main routine. _main is
  4491.     responsible for opening the stderr channel as well.  However, if you
  4492.     specify your own _main you will override the c.lib version.  Normally
  4493.     you either fall through or _exit from _main. A programmable can use
  4494.     the _main entry point when the executable uses nothing but system
  4495.     library routines.  That is, you make no calls to stdio functions such
  4496.     as puts, printf, etc., to low level IO routines such as open, close,
  4497.     read, etc., or malloc or any routine that uses malloc. Self contained
  4498.     routines such as strcpy may still be called, and, of course, you may
  4499.     open any libraries you wish and make library calls.  Since the
  4500.     auto-library opening and closing is done by the startup module (c.o),
  4501.     "dos.library" will still be opened for you automatically if you make
  4502.     any DOS calls.
  4503.  
  4504.     Using the _main entry point usually results in a substantially
  4505.     smaller executable because stdio and other library routines
  4506.     referenced by the c.lib. _main and exit are never referenced and thus
  4507.     never become part of the executable.  It is NOT SUGGESTED that
  4508.     beginning C programmers use the _main entry point.
  4509.  
  4510.     || NOTE: _main is called by the startup module whether the program
  4511.     || was run from the CLI or the WORKBENCH.  You must detect which
  4512.     || yourself and also deal with the WORKBENCH message yourself.
  4513.  
  4514.     int argc;        number of arguments
  4515.  
  4516.     char *argv;        array pointer to arguments
  4517.  
  4518.     SEE ALSO
  4519.     _exit, main, exit
  4520.  
  4521.     EXAMPLE
  4522.     /*
  4523.     **  This program comes in at under 600 bytes.
  4524.     */
  4525.     _main()
  4526.     {
  4527.        Write(Output(), "UG!\n", 4);
  4528.        _exit(0);
  4529.     }
  4530.  
  4531. dice/malloc                                                      dice/malloc
  4532.  
  4533.     FUNCTION
  4534.     allocate memory, the memory is NOT automatically cleared (ANSI)
  4535.  
  4536.     SYNTAX
  4537.     #include <stdlib.h>
  4538.     void *ptr = malloc(bytes);
  4539.     size_t bytes;
  4540.  
  4541.     DESCRIPTION
  4542.     malloc allocates the specified number of bytes of memory. The
  4543.     returned pointer is longword aligned; malloc returns NULL if the
  4544.     memory could not be allocated.
  4545.  
  4546.     || NOTE: Unlike calloc, malloc does not zero the memory before it
  4547.     || returns.
  4548.  
  4549.     INPUTS
  4550.     size_t bytes;        number of bytes to allocate
  4551.  
  4552.     RESULTS
  4553.     void *ptr;        pointer to base of allocated memory.  The memory
  4554.                 is not zero'd.
  4555.  
  4556.     SEE ALSO
  4557.     calloc, strdup
  4558.  
  4559. dice/memcmp                                                      dice/memcmp
  4560.  
  4561.     FUNCTION
  4562.     compare two memory buffers (ANSI)
  4563.  
  4564.     SYNTAX
  4565.     #include <string.h>
  4566.     int r = memcmp(s1, s2, bytes)
  4567.     void *s1;
  4568.     void *s2;
  4569.     size_t bytes;
  4570.  
  4571.     DESCRIPTION
  4572.     memcmp compares two memory buffers.  A byte by byte unsigned
  4573.     comparison is done.  When a comparison fails and the byte in s1 is
  4574.     less than the byte in s2 then -1 is returned.  If the byte in s1 is
  4575.     greater than the byte in s2 then 1 is returned.  If the count is
  4576.     exhausted and all comparisons succeed then 0 is returned indicating
  4577.     the two buffers are the same.
  4578.  
  4579.     INPUTS
  4580.     void *s1;        pointer to first buffer
  4581.  
  4582.     void *s2;        pointer to second buffer
  4583.  
  4584.     size_t bytes;        size of each buffer
  4585.  
  4586.     RESULTS
  4587.     int r;            -1 if buf s1 < buf s2, 0 if buf s1 == buf s2, 1
  4588.                 if buf s1 > buf s2.
  4589.  
  4590.     SEE ALSO
  4591.     memset, setmem, bzero, clrmem, bcopy, bcmp, movmem, memcpy, memmove
  4592.  
  4593.     EXAMPLE
  4594.     #include <stdlib.h>
  4595.     #include <assert.h>
  4596.  
  4597.     main()
  4598.     {
  4599.        unsigned char buf1[5] = {9, 10, 1, 12}; /* 1,729 */
  4600.        unsigned char buf2[5] = {9, 10, 1, 12}; /* 1,729 */
  4601.        int r;
  4602.  
  4603.        r = memcmp(buf1, buf2, 4);
  4604.        assert(r == 0);
  4605.        buf1[2] = 0;
  4606.        r = memcmp(buf1, buf2, 4);
  4607.        assert(r < 0);
  4608.        buf1[2] = 42;
  4609.        r = memcmp(buf1, buf2, 4);
  4610.        assert(r > 0);
  4611.        return(0);
  4612.     }
  4613.  
  4614. dice/memcpy,memmove,movmem,bcopy            dice/memcpy,memmove,movmem,bcopy
  4615.  
  4616.     FUNCTION
  4617.     memcopy: copy memory, ANSI, overlapped memory buffers illegal
  4618.     memmov: copy memory, ANSI, works with overlapped memory buffers
  4619.     movmem: copy memory, UNIX, works with overlapped memory buffers
  4620.     bcopy: copy memory, UNIX, works with overlapped memory buffers
  4621.  
  4622.     SYNTAX
  4623.     #include <string.h>
  4624.     void *ptr = memcpy(d, s, bytes);
  4625.     void *ptr = memmove(d, s, bytes);
  4626.     void *ptr = movmem(s, d, bytes);
  4627.     void *ptr = bcopy(s, d, bytes);
  4628.     void *d;
  4629.     void *s;
  4630.     size_t bytes;
  4631.  
  4632.     DESCRIPTION
  4633.     These functions copy memory from one region to another.  Unlike
  4634.     string routines these functions do not stop the copy when a NULL is
  4635.     encountered.
  4636.  
  4637.     ## WARNING: Be careful about argument ordering.  Some calls  take the
  4638.     ## source buffer first and other calls take the destination buffer
  4639.     ## first.
  4640.  
  4641.     The ANSI committee opted for a destination, source ordering rather
  4642.     than the more logical source, destination ordering. Thus, many
  4643.     programmers will use the non-standard movmem call instead of the ANSI
  4644.     memmove call.  The ANSI function 'memcpy' as defined by the ANSI
  4645.     standard cannot handle overlapped memory areas.  The Amiga
  4646.     implementation can but you should remember this if you intend to port
  4647.     your code.
  4648.  
  4649.     || NOTE: DICE's memory move optimizes the copy using movem when
  4650.     || possible, yielding very fast memory copies for large buffers. The
  4651.     || UNIX bcopy call exists for compatibility purposes and should not
  4652.     || be used with new programs.
  4653.  
  4654.     INPUTS
  4655.     void *s;        source buffer
  4656.  
  4657.     void *d;        destination buffer
  4658.  
  4659.     RESULTS
  4660.     void *ptr;        pointer to the destination buffer(d)
  4661.  
  4662.     SEE ALSO
  4663.     memset, setmem, bzero, clrmem, cmpmem, memcmp
  4664.  
  4665.     EXAMPLE
  4666.     /*
  4667.      * This example copies the entire buffer, not just
  4668.      * the part containing the string.  Normally one just
  4669.      * uses string routines.
  4670.      */
  4671.     #include <string.h>
  4672.     #include <assert.h>
  4673.  
  4674.     main()
  4675.     {
  4676.        char s[16];
  4677.        char d[16];
  4678.        void *p;
  4679.        strcpy(s, "This is a test");
  4680.        p = movmem(s, d, sizeof(s));
  4681.        assert(p == d);
  4682.        puts(d);
  4683.        strcpy(s, "Googolplex");
  4684.        p = bcopy(s, d, sizeof(s));
  4685.        assert(p == d);
  4686.        puts(d);
  4687.        strcpy(s, "EchoBeko");
  4688.        p = memcpy(d, s, sizeof(s));
  4689.        assert(p == d);
  4690.        puts(d);
  4691.        strcpy(s, "GakFuBar");
  4692.        p = memmove(d, s, sizeof(s));
  4693.        assert(p == d);
  4694.        puts(d);
  4695.        return(0);
  4696.     }
  4697.  
  4698. dice/memset,setmem,clrmem,bzero              dice/memset,setmem,clrmem,bzero
  4699.  
  4700.     FUNCTION
  4701.     memset: ANSI, set memory buffer to a byte value
  4702.     setmem: UNIX, set memory buffer to a byte value
  4703.     clrmem: DICE,  zero out a memory buffer
  4704.     bzero: UNIX, zero out a memory buffer
  4705.  
  4706.     SYNTAX
  4707.     #include <string.h>
  4708.     void *ptr = memset(buf, c, n);
  4709.     void *ptr = setmem(buf, n, c);
  4710.     void *ptr = clrmem(buf, n);
  4711.     void *ptr = bzero(buf, n);
  4712.     void *buf;
  4713.     int c;
  4714.     size_t n;
  4715.  
  4716.     DESCRIPTION
  4717.     These functions fill a memory buffer with the specified character c.
  4718.     C is converted to an unsigned character by the fill routine before
  4719.     beginning the fill.  N bytes are filled.
  4720.  
  4721.     ## WARNING: Again, watch out for argument ordering, especially for
  4722.     ## the ANSI memset call.
  4723.  
  4724.     The ANSI committee chose bizarre call ordering so there is another
  4725.     defacto standard call called setmem. The function bzero exists for
  4726.     UNIX compatibility, and clrmem is yet another call (this time
  4727.     introduced by DICE--sorry!). memset and setmem are the most portable
  4728.     calls.
  4729.  
  4730.     INPUTS
  4731.     void *buf;        pointer to buffer to fill
  4732.  
  4733.     int  c;         character to copy into buffer
  4734.  
  4735.     (setmem, memset) size_t n;
  4736.                 # of bytes to fill
  4737.  
  4738.     RESULTS
  4739.     void *ptr;        pointer to buffer (== buf).
  4740.  
  4741.     SEE ALSO
  4742.     malloc, calloc, strdup, movmem, cmpmem
  4743.  
  4744.     EXAMPLE
  4745.     #include <string.h>
  4746.     #include <assert.h>
  4747.     #include <stdlib.h>
  4748.     main()
  4749.     {
  4750.        char buf[32];
  4751.        char *b;
  4752.        b = setmem(buf, 32, 0);
  4753.        assert(b == buf);
  4754.        b = setmem(buf, 4, 'a');
  4755.        b = memset(buf + 4, 'b' , 4);
  4756.        puts(buf);       /*  aaaabbbb    */
  4757.        return(0);
  4758.     }
  4759.  
  4760. dice/mkdir                                                        dice/mkdir
  4761.  
  4762.     FUNCTION
  4763.     create a directory (UNIX)
  4764.  
  4765.     SYNTAX
  4766.     #include <stdio.h>
  4767.     int error = mkdir(dirname)
  4768.     char *dirname;
  4769.  
  4770.     DESCRIPTION
  4771.     mkdir creates a new directory.    It returns 0 if successful, -1 if not
  4772.     (with errno set to an error code).
  4773.  
  4774.     INPUTS
  4775.     char *dirname;        filename of directory to create
  4776.  
  4777.     RESULTS
  4778.     int r;            0 if no error, < 0 if error
  4779.  
  4780.     SEE ALSO
  4781.     close, creat, fcntl, fdtofh, getfh, ioctl, isatty, lseek, mkdir,
  4782.     open, read, rmdir, unlink, write
  4783.  
  4784.     EXAMPLE
  4785.     main()
  4786.     {
  4787.        int r;
  4788.        r = mkdir("T:tmpdir");
  4789.        if (r == 0)
  4790.           puts("Created T:tmpdir successfully");
  4791.        else
  4792.           puts("Unable to create directory T:tmpdir");
  4793.     }
  4794.  
  4795. dice/_mods,_modu                                            dice/_mods,_modu
  4796.  
  4797.     FUNCTION
  4798.     signed/unsigned long modulus 32 (DICE)
  4799.  
  4800.     DESCRIPTION
  4801.     These are assembly functions that DICE uses whenever it needs to do a
  4802.     long modulus.  The functions are not callable from C.
  4803.  
  4804.     INPUTS
  4805.     D0            32 bit signed/unsigned integer
  4806.  
  4807.     D1            32 bit signed/unsigned integer
  4808.  
  4809.     RESULTS
  4810.     D0            Remainder of D0 divided by D1
  4811.  
  4812.     SEE ALSO
  4813.     _divs, _divu, _muls, _mulu
  4814.  
  4815. dice/_muls,_mulu                                            dice/_muls,_mulu
  4816.  
  4817.     FUNCTION
  4818.     signed/unsigned long multiply (DICE)
  4819.  
  4820.     DESCRIPTION
  4821.     These are assembly functions that DICE uses whenever it needs to do
  4822.     long multiplication.  They are not callable from C.
  4823.  
  4824.     INPUTS
  4825.     D0            32 bit signed/unsigned integer
  4826.  
  4827.     D1            32 bit signed/unsigned integer
  4828.  
  4829.     RESULTS
  4830.     D0            D0 multiplied by D1
  4831.  
  4832.     SEE ALSO
  4833.     _divs, _divu, _mods, _modu
  4834.  
  4835. dice/onbreak                                                    dice/onbreak
  4836.  
  4837.     FUNCTION
  4838.     Set special ^C handler (AmigaDOS)
  4839.  
  4840.     SYNTAX
  4841.     typedef int (*fptr)();
  4842.     fptr oldfunc = onbreak(newfunc);
  4843.     fptr newfunc;
  4844.  
  4845.     DESCRIPTION
  4846.     onbreak sets a special function to handle ^C.  It takes a pointer to
  4847.     this function and returns a pointer to the previous onbreak function,
  4848.     if any.  When ^C is hit, the special onbreak function is called
  4849.     before any other action. If the onbreak function returns a non-zero
  4850.     value, ^C aborts the program like it usually does.  If the function
  4851.     returns 0, however, the ^C is completely ignored.
  4852.  
  4853.     INPUTS
  4854.     newfunc         pointer to function or NULL
  4855.  
  4856.     RESULTS
  4857.     fptr oldfunc;        pointer to previous onbreak function
  4858.  
  4859.     SEE ALSO
  4860.     atexit
  4861.  
  4862.     EXAMPLE
  4863.     /*
  4864.     * Note: The reentrancy check is needed because of both
  4865.     * the puts and the sleep() call.
  4866.     */
  4867.     #include <stdio.h>
  4868.     #include <stdlib.h>
  4869.  
  4870.     int brk()
  4871.     {
  4872.        static short cnt = 0; /*  check for reentrancy */
  4873.        if (cnt)         /*  if not 0 then reentered! */
  4874.           return(0);
  4875.           ++cnt;
  4876.        puts("Nah Nah, you can't break me!");
  4877.        sleep(1);
  4878.        --cnt;
  4879.        return(0);
  4880.     }
  4881.  
  4882.     int main()
  4883.     {
  4884.        short i;
  4885.        onbreak(brk);
  4886.        puts("Hit ^C while I loop from 1 to 100.");
  4887.        sleep(2);
  4888.        for (i = 1; i <= 100; ++i)
  4889.        printf("Loop, counting, count = %d\n", i);
  4890.        return(0);
  4891.     }
  4892.  
  4893. dice/open                                                          dice/open
  4894.  
  4895.     FUNCTION
  4896.     open a file (UNIX)
  4897.  
  4898.     SYNTAX
  4899.     #include <fcntl.h>
  4900.     int fd = open(name, modes);
  4901.     char *name;
  4902.     int modes;
  4903.  
  4904.     DESCRIPTION
  4905.     open opens a file of the specified name using the specified modes.
  4906.     The combinations yield different results as described below:
  4907.  
  4908.     O_RDONLY  : open file for reading only
  4909.     ----------+----------------------------------------------------------
  4910.     O_WRONLY  : open file for writing only
  4911.     ----------+----------------------------------------------------------
  4912.     O_RDWR      : open file for reading and writing
  4913.     ----------+----------------------------------------------------------
  4914.     O_NDELAY  : open file non-blocking (not implemented)
  4915.     ----------+----------------------------------------------------------
  4916.     O_APPEND  : open file for writing only and force all writes to
  4917.           : append to the file regardless of the current seek
  4918.           : position.  open is a lower-level construct than the more
  4919.           : standard fopen.
  4920.     ----------+----------------------------------------------------------
  4921.  
  4922.  
  4923.     O_CREAT creates the file if it does not exist; O_TRUNC truncates the
  4924.     file if it does exist; O_EXCL is used only with O_CREAT and if the
  4925.     file already exists the open will fail; O_BINARY opens the file for
  4926.     binary reading and writing, vs text.  This flag is ignored by DICE
  4927.     since there is no difference on the Amiga.  However, on Messy-DOS
  4928.     systems, CR-LF must be converted to an LF when reading text files.
  4929.     open returns a descriptor (>= 0) or error (< 0) on failure.
  4930.  
  4931.     || NOTE: Refer to the file_descriptor manual page for general
  4932.     || information. Unlike file pointers and file handles, the file
  4933.     || descriptor is checked for validity and will simply return an error
  4934.     || if illegal.
  4935.  
  4936.     INPUTS
  4937.     char *name;        filename to open
  4938.  
  4939.     long modes;        modes to open the file with
  4940.  
  4941.     RESULTS
  4942.     int fd;         A file descriptor if >= 0, an error if < 0.
  4943.  
  4944.     SEE ALSO
  4945.     close, creat, fcntl, fdtofh, fopen, ioctl, isatty, lseek, mkdir,
  4946.     read, rmdir, unlink, write
  4947.  
  4948.     EXAMPLE
  4949.     #include <fcntl.h>
  4950.     #include <assert.h>
  4951.     main()
  4952.     {
  4953.        int fd, r;
  4954.        fd = open("T:xx", O_WRONLY|O_CREAT|O_TRUNC);
  4955.        assert(fd >= 0);
  4956.        close(fd);
  4957.        fd = open("T:xx", O_CREAT|O_EXCL|O_TRUNC|O_WRONLY);
  4958.        assert(fd < 0);  /* will fail, file already exists */
  4959.        remove("T:xx");
  4960.        fd = open("T:xx", O_CREAT|O_TRUNC|O_WRONLY);
  4961.        assert(fd >= 0); /* will work     */
  4962.        write(fd, "FuBar-", 6);
  4963.        lseek(fd, 0L, 0);  /*  seek back to start of file */
  4964.        r = write(fd, "XxXxx", 5);
  4965.        assert(r == 5);
  4966.        close(fd);
  4967.        fd = open("T:xx", O_APPEND|O_WRONLY);
  4968.        assert(fd >= 0);
  4969.        write(fd, "FuBar\n", 6);
  4970.        close(fd);
  4971.        printf("type t:xx should return \"XxXXX-FuBar\"\n");
  4972.        return(0);
  4973.     }
  4974.  
  4975. dice/perror                                                      dice/perror
  4976.  
  4977.     FUNCTION
  4978.     output error message associated with errno and text to stderr (ANSI)
  4979.  
  4980.     SYNTAX
  4981.     #include <stdio.h>
  4982.     void perror(str);
  4983.     const char *str;
  4984.  
  4985.     DESCRIPTION
  4986.     perror outputs the specified string, a colon, and the error number
  4987.     and error message associated with the current value of errno to
  4988.     stderr, ending with a newline.    Using perror is a common way to
  4989.     generate error messages due to IO failures.
  4990.  
  4991.     INPUTS
  4992.     char *str;        string message to include in error output
  4993.  
  4994.     EXAMPLE
  4995.     #include <stdio.h>
  4996.     main()
  4997.     {
  4998.        FILE *fp = fopen("T:DoesNotExist", "r");
  4999.        if( fp ) {
  5000.           puts("T:DoesNotExist is not supposed to exist!");
  5001.           exit(1);
  5002.        }
  5003.        perror("fopen");
  5004.        return(0);
  5005.     }
  5006.  
  5007. dice/PlaceRexxCommand                                  dice/PlaceRexxCommand
  5008.  
  5009.     FUNCTION
  5010.     Send a command to ARexx (DICE)
  5011.  
  5012.     SYNTAX
  5013.     #include <lib/rexx.h>
  5014.     rc = PlaceRexxCommand(port, str, &res, &ec)
  5015.     struct MsgPort *port;
  5016.     char *str;
  5017.     char *res;
  5018.     long ec;
  5019.  
  5020.     DESCRIPTION
  5021.     PlaceRexxCommand sends an ARexx command off to ARexx. (compare to
  5022.     PlaceRexxCommandDirect which talks to an application) The command is
  5023.     normally a script file to run.    You must specify the ARexx port that
  5024.     is to act as the default host port for the command or NULL to use
  5025.     DICE's default port. The default extension for the script is always
  5026.     the RexxHostName variable.  Note that if you specify NULL for the
  5027.     port to use DICE's default, then you must have previously setup
  5028.     DICE's default port.  This occurs automatically if RexxHostName was
  5029.     declared non-NULL, or manually if you had called
  5030.     Create[Global]DiceRexxPort(NULL, "name").
  5031.  
  5032.     You supply the command in str which is passed to ARexx as  Arg0.
  5033.     Currently there is no support for additional arguments.  DICE will
  5034.     run the command synchronously and return the result code.
  5035.  
  5036.     The result string pointer will be set to either NULL or a malloc()'d
  5037.     string.  If not NULL you are responsible for free()ing the result
  5038.     string when you are through with it!!  If you wish to ignore any
  5039.     result you may pass NULL for this argument.
  5040.  
  5041.     The ec longword will be set to an internal ARexx error code... if the
  5042.     returned result code is non-zero and ec == 1 then ARexx was unable to
  5043.     find the specified ARexx command.  You may pass NULL for this
  5044.     argument if you do not care about the error code.
  5045.  
  5046.     It is possible that your program will receive ARexx commands while it
  5047.     is waiting for the command you have sent to be returned.  DICE will
  5048.     automatically call DoRexxCommand() from within the PlaceRexxCommand()
  5049.     routine when this case occurs.
  5050.  
  5051.     ARexx will set the error-code ec, which is different from the
  5052.     result-code.  ec is set to 1 if the script could not be found. ARexx
  5053.     normally returns a severity code of 5 for this case.  If the return
  5054.     code is 0 then ec will be 0.
  5055.  
  5056.     INPUTS
  5057.     struct MsgPort *port;
  5058.                 Message port for processing.  Typically you pass
  5059.                 NULL to use the default port.
  5060.  
  5061.     char *str;        String to be passed to ARexx for execution
  5062.  
  5063.     char **res;        Pointer to place to store result string from
  5064.                 ARexx.  NULL indicates no result is desired.
  5065.  
  5066.     long *ec;        Pointer to place to store error code from ARexx.
  5067.                 Set to 1 for script not found.  NULL indicates no
  5068.                 result code desired.
  5069.  
  5070.     RESULTS
  5071.     int rc;         Return code from ARexx
  5072.  
  5073.     SEE ALSO
  5074.     DoRexxCommand, PlaceRexxCommandDirect, ProcessRexxCommands
  5075.  
  5076.     EXAMPLE
  5077.     See DICE ARexx Support in chapter
  5078.  
  5079. dice/PlaceRexxCommandDirect                      dice/PlaceRexxCommandDirect
  5080.  
  5081.     FUNCTION
  5082.     Send an ARexx command to an Application (DICE)
  5083.  
  5084.     SYNTAX
  5085.     #include <lib/rexx.h>
  5086.     rc = PlaceRexxCommandDirect(port, apport,str, &res, &ec);
  5087.     struct MsgPort *port;
  5088.     char *apport;
  5089.     char *str;
  5090.     char *res;
  5091.     long ec;
  5092.  
  5093.     DESCRIPTION
  5094.     PlaceRexxCommandDirect sends an ARexx command to a specification
  5095.     application (compare to PlaceRexxCommand which talks to ARexx
  5096.     directly). The command is normally a script file to run.  You must
  5097.     specify the ARexx port that is to act as the default host port for
  5098.     the command or NULL to use DICE's default port. The default extension
  5099.     for the script is always the RexxHostName variable.  Note that if you
  5100.     specify NULL for the port to use DICE's default, then you must have
  5101.     previously setup DICE's default port.  This occurs automatically if
  5102.     RexxHostName was declared non-NULL, or manually if you had called
  5103.     Create[Global]DiceRexxPort(NULL, "name").
  5104.  
  5105.     You supply the command in str which is made Arg0.  Currently there is
  5106.     no support for additional arguments.  DICE will run the command
  5107.     synchronously and return the result code.
  5108.  
  5109.     The result string pointer will be set to either NULL or a malloc()'d
  5110.     string.    If you wish to ignore any result you may pass NULL for
  5111.     this argument.
  5112.  
  5113.     || NOTE: If you do not pass NULL, you are responsible for free()ing
  5114.     || the result string when you are through with it!
  5115.  
  5116.     The ec longword will be set to an internal ARexx error code... if the
  5117.     returned result code is non-zero and ec == 1 then ARexx was unable to
  5118.     find the specified ARexx command.  You may pass NULL for this
  5119.     argument if you do not care about the error code.
  5120.  
  5121.     It is possible that your program will receive ARexx commands while it
  5122.     is waiting for the command you have sent to be returned.  DICE will
  5123.     automatically call DoRexxCommand() from within the PlaceRexxCommand()
  5124.     routine when this case occurs.
  5125.  
  5126.     ARexx will set the error-code ec, which is different from the
  5127.     result-code.  ec is set to 1 if the script could not be found. ARexx
  5128.     normally returns a severity code of 5 for this case.  If the return
  5129.     code is 0 then ec will be 0.
  5130.  
  5131.     INPUTS
  5132.     struct MsgPort *port;
  5133.                 Message port for processing.  Typically you pass
  5134.                 NULL to use the default port.
  5135.  
  5136.     char *apport;        Name of application to send commands to.
  5137.  
  5138.     char *str;        String to be passed to ARexx for execution
  5139.  
  5140.     char **res;        Pointer to place to store result string from
  5141.                 ARexx.  NULL indicates no result is desired.
  5142.  
  5143.     long *ec;        Pointer to place to store error code from ARexx.
  5144.                 Set to 1 for script not found.  NULL indicates no
  5145.                 result code desired.
  5146.  
  5147.     RESULTS
  5148.     int rc;         Return code from ARexx
  5149.  
  5150.     SEE ALSO
  5151.     DoRexxCommand, PlaceRexxCommand, ProcessRexxCommands
  5152.  
  5153.     EXAMPLE
  5154.     See DICE ARexx Support in chapter
  5155.  
  5156. dice/pow,fpow                                                  dice/pow,fpow
  5157.  
  5158.     FUNCTION
  5159.     pow: return one double to the power of another (ANSI)
  5160.     fpow: return one float to the power of another (ANSI)
  5161.  
  5162.     LIBRARY
  5163.     m.lib
  5164.  
  5165.     SYNTAX
  5166.     #include <math.h>
  5167.     double a = pow(b, bp);
  5168.     double bp;
  5169.     double b;
  5170.     float  c = flog(d, dp);
  5171.     float  dp; float  d;
  5172.  
  5173.     DESCRIPTION
  5174.     pow returns one double to the power of another; fpow returns one
  5175.     float to the power of another.
  5176.  
  5177.     INPUTS
  5178.     double b;        double floating point value (base)
  5179.  
  5180.     double bp;        double floating point value (exponent)
  5181.  
  5182.     float d;        float floating point value (base)
  5183.  
  5184.     float dp;        float floating point value (exponent)
  5185.  
  5186.     RESULTS
  5187.     double a;        double floating point value
  5188.  
  5189.     float c;        float floating point value
  5190.  
  5191.     SEE ALSO
  5192.     acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan
  5193.     facos, fasin
  5194.  
  5195.     EXAMPLE
  5196.     /*
  5197.      *  compile with the math library -lm
  5198.      */
  5199.     #include <math.h>
  5200.     #include <stdio.h>
  5201.     main()
  5202.     {
  5203.        {
  5204.           double a = pow(0.25, 4.0);
  5205.           printf("pow 0.25 ^^ 4.0 = %lf\n", a);
  5206.           /*  0.0039 */
  5207.        }
  5208.        {  /*  less accuracy  */
  5209.           float a = fpow(0.25, 4.0);
  5210.           printf("pow 0.25 ^^ 4.0 = %lf\n", (double)a);
  5211.        }
  5212.        return(0);
  5213.     }
  5214.  
  5215. dice/printf,fprintf,sprintf,vprintf,vfprintf,vsprintf
  5216.  
  5217.     FUNCTION
  5218.     formatted output to stdout, file pointer, or buffer (ANSI)
  5219.  
  5220.     SYNTAX
  5221.     #include <stdio.h>
  5222.     #include <stdarg.h> /* for v[f/s]printf() only */
  5223.     int n = printf(fmt, ...);
  5224.     int n = fprintf(fp, fmt, ...);
  5225.     int n = sprintf(buf, fmt, ...);
  5226.     int n = vprintf(fmt, argvect);
  5227.     int n = vfprintf(fp, fmt, argvect);
  5228.     int n = vsprintf(buf, fmt, argvect);
  5229.     FILE *fp;
  5230.     char *fmt;
  5231.     char *buf;
  5232.     va_list argvect;
  5233.  
  5234.     DESCRIPTION
  5235.     These functions offer formatted printing in various flavors. printf
  5236.     and vprintf output to stdout;  fprintf and vfprintf output to a file
  5237.     pointer (fp); sprintf and vsprintf output to a character buffer.  All
  5238.     routines return the number of characters written if successful, a
  5239.     negative number if not.  Only sprintf and vsprintf are limited in
  5240.     terms of output size (it cannot exceed the buffer you give it). The
  5241.     common argument to all routines is the format specifier.  The format
  5242.     specifier is scanned to determine how to handle the arguments to the
  5243.     call (or the argument list for vfprintf/vsprintf). Characters are
  5244.     copied to the output until a % is encountered. %% indicates a literal
  5245.     '%' character.  Otherwise, the % is followed by a control sequence
  5246.     that tells printf how to output the corresponding argument.  The
  5247.     quantity is output and the scan continues until the end of the format
  5248.     string.  The % formats are interpreted as follows:
  5249.  
  5250.     %[flags][#[.#]][modifier]<conversion-specifier>
  5251.     Items in brackets are optional.  After the %, zero or more flags may
  5252.     be specified.  Then, an optional integer which represents the minimum
  5253.     field width for the object may also be specified.  If an integer is
  5254.     specified it may be followed by a period and another integer that
  5255.     represents that precision with which a number is printed. Zero or
  5256.     more modifiers may then be specified followed by a mandatory
  5257.     conversion specifier.
  5258.  
  5259.     Either or both integers (#[.#]) may be specified as a '*', as in
  5260.     "%*d", specifying that the minimum field width and/or precision is
  5261.     specified as an integer in the argument that occurs before the
  5262.     conversion object.  For example, printf("--%*d--\n", 10, 23); would
  5263.     print the number 23 right justified in a field 10 characters wide.
  5264.  
  5265.     Conversion Flags
  5266.     ----------------
  5267.  Minus (-)  Left justify text within the field.
  5268.  
  5269.    <space>  This flag places a blank in front of positive signed numbers, and
  5270.         a minus in front of negative numbers.  This option allows columns
  5271.         of positive and negative numbers to line up.
  5272.  
  5273.   Plus (+)  Cause a plus sign to be placed before a positive result.  A minus
  5274.         sign is always placed before a negative result.
  5275.  
  5276.  Pound (#)  Format output according to the type of input.  e, E, f, F always
  5277.         retains the decimal point.    g, G always retains the decimal
  5278.         point, and trailing zeros are kept.  x and X print '0x' and '0X'
  5279.         respectively before the number (except that this is not currently
  5280.         implemented by DICE).
  5281.  
  5282.      0  Pad columns with zeros instead of spaces.  Ignored if a precision
  5283.         is specified or if the '-' flag is specified.
  5284.  
  5285.     Modifiers
  5286.     ---------
  5287.      h  Indicates the corresponding integer argument is a short or an
  5288.         unsigned short (stands for "half-size").  Affects scanf(), but
  5289.         since DICE uses 32 bit integers, has no effect on printf().
  5290.  
  5291.      l  Indicates the corresponding integer argument is a long or
  5292.         unsigned long.  Also indicates floating point argument is a
  5293.         double (else is a float). Under DICE this flag is superfluous for
  5294.         integers, but for portability reasons you want to specify it when
  5295.         an argument is explicitly a long.
  5296.  
  5297.     Conversion Specifiers
  5298.     ---------------------
  5299.      c  Output integer as a character.
  5300.  
  5301.      d  Output a signed integer.
  5302.  
  5303.      e  Output a double quantity in exponential form. The precision
  5304.         specifies the number of digits beyond the decimal point to print,
  5305.         ie: [-]d.dddddde+/-dd.
  5306.  
  5307.      E  Upper case version of e.
  5308.  
  5309.      f  Output a double quantity. The precision specifies the number of
  5310.         digits beyond the decimal point to print, ie:  [-]d.dddddd
  5311.  
  5312.      g  Output a double quantity using either the 'e' or 'f' form,
  5313.         depending on the exponent.
  5314.  
  5315.      G  Output a double quantity using either the 'E' or 'f' form,
  5316.         depending on the exponent.
  5317.  
  5318.      i  Same as 'd', but less portable.
  5319.  
  5320.      n  The argument is a pointer to an integer which is used to set the
  5321.         integer to the bytes written out so far. This is especially
  5322.         useful with sprintf to determine where a particular part of the
  5323.         format begins in the output buffer.
  5324.  
  5325.      o  The unsigned integer quantity is converted to ASCII-octal.
  5326.  
  5327.      p  The pointer is printed (basically the hexadecimal address is
  5328.         printed).
  5329.  
  5330.      s  The NULL-terminated string represented by the character pointer
  5331.         is printed.
  5332.  
  5333.      u  The unsigned integer quantity is converted to ASCII-decimal.
  5334.  
  5335.      x  The unsigned integer quantity is converted to ASCII-hex using
  5336.         '0'-'9', 'a'-'f'.
  5337.  
  5338.      X  The unsigned integer quantity is converted to ASCII-hex using
  5339.         upper case 'A'-'F' instead of lower case.
  5340.  
  5341.     INPUTS
  5342.     FILE *fp;        file pointer (fprintf, vfprintf)
  5343.  
  5344.     char *fmt;        format string, e.g. "Answer is %d\n"
  5345.  
  5346.     char *buf;        buffer (sprintf, vsprintf)
  5347.  
  5348.     va_list argvect;    arg list (vprintf, vfprintf, vsprintf)
  5349.  
  5350.     RESULTS
  5351.     int n;            Number of characters written if successful, a
  5352.                 negative number if not.  For sprintf and vsprintf
  5353.                 the NULL character at the end of the string is
  5354.                 NOT included in the count.
  5355.  
  5356.     SEE ALSO
  5357.     puts, fputs, fwrite
  5358.  
  5359.     EXAMPLE
  5360.     /*
  5361.     **  Example using most printf conversion specifiers.
  5362.     **  Compile with -lm for the math functions to operate.
  5363.     */
  5364.     #include <stdio.h>
  5365.     #include <stdarg.h>
  5366.     void test_varargs(); /* Always use function prototypes */
  5367.     main()
  5368.     {
  5369.     char buf[256];
  5370.     int  n, i;
  5371.  
  5372.        printf(
  5373.        "Normal: ab%c %03d %03o $%p  Fu%s  %u    $%x  $%8X $%08lX\n",
  5374.               'c', 43,  11,  buf, "Bar",32094,4095,4095,4095 );
  5375.  
  5376.        printf(
  5377.         "Math:   Double: %le Float: %lf Formatted Float: %2.2lf\n",
  5378.              1.23E-2,   1.23E-2,               1.257 );
  5379.  
  5380.        printf("%9s\n",    "<-"); /* Specify 9 character field width */
  5381.        printf("%*s\n", 9, "<-"); /* Indirect specification */
  5382.  
  5383.        n = sprintf(buf, "Save %n%s", &i, "the whales");
  5384.        puts(buf);
  5385.        printf("String is %d+1 bytes long,"  /* String Concatenation */
  5386.           "with a %%n token at %d.\n", n, i);
  5387.  
  5388.        fprintf(stdout, "\nThis is a call to %s\n", "fprintf");
  5389.  
  5390.        test_varargs("%d %d %d ", 1, 2, 3);
  5391.  
  5392.        return(0);
  5393.     }
  5394.  
  5395.     void test_varargs(ctl, ...)
  5396.     char *ctl;
  5397.     {
  5398.        va_list va;
  5399.        int n;
  5400.        va_start(va, ctl);
  5401.        n = vprintf(ctl, va);
  5402.        printf("<- %d chars written\n", n);
  5403.        va_end(va);
  5404.     }
  5405.  
  5406. dice/ProcessRexxCommands                            dice/ProcessRexxCommands
  5407.  
  5408.     FUNCTION
  5409.     Handle incomming ARexx commands (DICE)
  5410.  
  5411.     SYNTAX
  5412.     #include <lib/rexx.h>
  5413.     ProcessRexxCommands(port)
  5414.     struct MsgPort *port;
  5415.  
  5416.     DESCRIPTION
  5417.     In order to process incomming ARexx commands you must call
  5418.     ProcessRexxCommands when you receive the signal RexxSigBit (signal
  5419.     mask is (1 << RexxSigBit)).
  5420.  
  5421.     Passing NULL to this routine will cause DICE to scan ALL KNOWN ARexx
  5422.     ports belonging to this program... that is, the master port and all
  5423.     created ports.    DICE will call DoRexxCommand for each ARexx command
  5424.     received as well as weed out returned messages from any ARexx
  5425.     commands we have sent that are still in progress.
  5426.  
  5427.     If you wish, you can pass a specific message port to have DICE only
  5428.     process ARexx commands received on a specific port, but beware that
  5429.     your Wait on the signal bit has cleared the signal and you should be
  5430.     sure to process all message ports before calling Wait again, else
  5431.     risk leaving unprocessed ARexx messages queued in and then blocking
  5432.     in Wait.
  5433.  
  5434.     INPUTS
  5435.     struct MsgPort *port;
  5436.                 Message port to process or NULL to process all
  5437.                 ports.
  5438.  
  5439.     SEE ALSO
  5440.     DoRexxCommand, PlaceRexxCommand, PlaceRexxCommandDirect
  5441.  
  5442.     EXAMPLE
  5443.     See DICE ARexx Support in chapter
  5444.  
  5445. dice/putchar                                                    dice/putchar
  5446.  
  5447.     FUNCTION
  5448.     output character to stdout (ANSI)
  5449.  
  5450.     SYNTAX
  5451.     #include <stdio.h>
  5452.     int r = putchar(c); /* MACRO */
  5453.  
  5454.     DESCRIPTION
  5455.     putchar outputs a character to stdout, returning the output character
  5456.     unless an error occurred.  If an error occurred then EOF is returned.
  5457.  
  5458.     || NOTE: Refer to the file_pointer manual page for general
  5459.     || information.
  5460.  
  5461.     INPUTS
  5462.     int c;            character to output, 0 to 255
  5463.  
  5464.     RESULTS
  5465.     int r;            same as c unless error occurred in which case
  5466.                 EOF.
  5467.  
  5468.     SEE ALSO
  5469.     putc, fputc, fread, fwrite, getc, getchar
  5470.  
  5471.     EXAMPLE
  5472.     /*
  5473.      * copy stdin to stdout using getchar/putchar. Normally
  5474.      * one uses fread/fwrite, but I'll save that for the
  5475.      * fread manual page.  Note that I output the initial
  5476.      * message to stderr so it does not get stuck into stdout
  5477.      * in case the user has redirected stdout.
  5478.      *
  5479.      * See getc manual page for equivalent example using
  5480.      * getc/putc
  5481.      */
  5482.     #include <stdio.h>
  5483.     main()
  5484.     {
  5485.          int c;
  5486.          fputs("Type a couple of lines, then ^\\ (EOF)\n",
  5487.             stderr);
  5488.          while ((c = getchar()) != EOF)
  5489.          {
  5490.         putchar(c);
  5491.          }
  5492.          return(0);
  5493.     }
  5494.  
  5495. dice/qsort                                                        dice/qsort
  5496.  
  5497.     FUNCTION
  5498.     sort an array of objects (ANSI)
  5499.  
  5500.     SYNTAX
  5501.     #include <stdio.h>
  5502.     #include <stdlib.h>
  5503.     (void) qsort(array, numElem, elemSize, compare_func)
  5504.     void *array;
  5505.     size_t numElem;
  5506.     size_t elemSize;
  5507.     int (*comp_func)(const void *arg1, const void *arg2);
  5508.  
  5509.     DESCRIPTION
  5510.     qsort sorts numElem elements in an array based at array. Each element
  5511.     is elemSize bytes long. When a comparison is required, qsort calls
  5512.     the passed compare_func function pointer with a pointer to the two
  5513.     elements being sorted. DICE currently implements qsort with a simple
  5514.     merge sort algorithm, using relatively slow movmems to avoid having
  5515.     to allocate much additional storage. Very little stack is used.
  5516.     Traditional qsort employs a stack based quick-sort algorithm that
  5517.     might use a massive amount of stack.
  5518.  
  5519.     INPUTS
  5520.     void *array;        pointer to base of array of objects
  5521.  
  5522.     size_t numElem;     number of elements in the array
  5523.  
  5524.     size_t elemSize;    size, in bytes, of each element
  5525.  
  5526.     int (*comp_func)()
  5527.                 function pointer to compare function given
  5528.                 pointers to two of the elements
  5529.  
  5530.     EXAMPLE
  5531.     #include <stdio.h>
  5532.     #include <stdlib.h>
  5533.     #define NUM_GENIUS 8
  5534.     char *StrList[NUM_GENIUS] =
  5535.     {
  5536.        "Euler", "Einstein", "Pascal", "Zeno",
  5537.        "Godel", "Leibniz", "Euclid", "Von Neumann"
  5538.     };
  5539.     my_comp(s1, s2)
  5540.     char **s1; char **s2;
  5541.     {
  5542.        return(strcmp(*s1, *s2));
  5543.     }
  5544.     main()
  5545.     {
  5546.        short i;
  5547.        qsort(StrList, NUM_GENIUS, sizeof(char *), my_comp);
  5548.        for (i = 0; i < NUM_GENIUS; ++i)
  5549.           printf("%d %s\n", i, StrList[i]);
  5550.        return(0);
  5551.     }
  5552.  
  5553. dice/raise                                                        dice/raise
  5554.  
  5555.     FUNCTION
  5556.     raise a signal (cause an 'interrupt' synchronously) (ANSI)
  5557.  
  5558.     SYNTAX
  5559.     int r = raise(signo);
  5560.     int signo;
  5561.  
  5562.     DESCRIPTION
  5563.     raise causes a signal to occur and the appropriate action to be
  5564.     taken.    It returns 0 on success, -1 if the signo is invalid (outside
  5565.     the range of allowed signals).    When you raise a signal, the signal
  5566.     is set back to its default vector before the handler is called.
  5567.     Thus, if you are allowing multiple signals to occur you MUST restore
  5568.     the signal vector with signal from your signal handler before it
  5569.     returns.
  5570.  
  5571.     INPUTS
  5572.     int signo;        signal to cause
  5573.  
  5574.     RESULTS
  5575.     int r;            0 on success, -1 if signo is out of range.
  5576.  
  5577.     SEE ALSO
  5578.     signal
  5579.  
  5580.     EXAMPLE
  5581.     /*
  5582.      *  prints the numbers 0 to 99, except only gets
  5583.      *  to 50 because we 'cause' a ^C.
  5584.      */
  5585.     #include <signal.h>
  5586.     main()
  5587.     {
  5588.        short i;
  5589.        for (i = 0; i < 100; ++i) {
  5590.           printf("i = %d\n", i);
  5591.           if (i == 50)
  5592.           raise(SIGINT);
  5593.         }
  5594.         return(0);
  5595.     }
  5596.  
  5597. dice/rand                                                          dice/rand
  5598.  
  5599.     FUNCTION
  5600.     return pseudo-random number (ANSI)
  5601.  
  5602.     SYNTAX
  5603.     #include <stdio.h>
  5604.     #include <stdlib.h>
  5605.     int n = rand(void);
  5606.     (void) srand(seed)
  5607.     unsigned int seed;
  5608.  
  5609.     DESCRIPTION
  5610.     rand returns a random number as a positive integer ranging from 0 to
  5611.     RAND_MAX.  RAND_MAX is defined in stdlib.h and is at least 32767.
  5612.      DICE implements it as 2147483647 == 0x7FFFFFFF.
  5613.     The initial seed used to generate the pseudo-random sequence is 1,
  5614.     but may be reinitialized to any number you desire using srand. rand
  5615.     is guaranteed to return the same sequence for the same seed.
  5616.  
  5617.     INPUTS
  5618.     none
  5619.  
  5620.     RESULTS
  5621.     int n;            returned by rand(), this number will be a
  5622.                 positive integer.
  5623.  
  5624.     SEE ALSO
  5625.     srand
  5626.  
  5627.     EXAMPLE
  5628.     #include <stdio.h>
  5629.     #include <stdlib.h>
  5630.  
  5631.     main(int ac, char**av)
  5632.     {
  5633.        short i;
  5634.        short j;
  5635.        if (ac == 2) {
  5636.           int seed =
  5637.           strtol(av[1], NULL, 0);
  5638.           srand(seed);
  5639.           printf("using seed = %d\n",
  5640.           seed);
  5641.        }
  5642.        else
  5643.           puts("using seed = 1");
  5644.  
  5645.        for (i = 0; i < 10; ++i) {
  5646.           int n = rand();
  5647.           printf("Random number: %08lx\t(%d)\n", n, n);
  5648.        }
  5649.        for (i = 0; i < 31; ++i) {
  5650.           int isone = 0;
  5651.           long mask = 1 << i;
  5652.           for (j = 0; j < 32767; ++j) {
  5653.          if (rand() & mask) ++isone;
  5654.           }
  5655.           printf("bit %d %5d:%-5d (deviation %d)\n", i,
  5656.               32767 - isone, isone, 16384 -isone);
  5657.        }
  5658.        return(0);
  5659.     }
  5660.  
  5661. dice/read                                                          dice/read
  5662.  
  5663.     FUNCTION
  5664.     read data from a file (UNIX)
  5665.  
  5666.     SYNTAX
  5667.     #include <fcntl.h>
  5668.     int r = read(fd, buf, bytes);
  5669.     int fd;
  5670.     void *buf;
  5671.     int bytes;
  5672.  
  5673.     DESCRIPTION
  5674.     read reads data from a file starting at the current seek position.
  5675.     read returns the number of bytes read or -1 if a read error occurs.
  5676.     With normal files, read will always return the number of bytes
  5677.     requested until the end of file is reached, in which case read may
  5678.     return fewer than the number of bytes requested.  If at the end of a
  5679.     file, read will return 0. With devices read may or may not return the
  5680.     number of bytes requested depending on the device.
  5681.  
  5682.     || NOTE: Refer to the file_descriptor manual page for general
  5683.     || information Unlike file pointers and file handles, the file
  5684.     || descriptor is checked for validity and will simply return an error
  5685.     || if illegal.
  5686.  
  5687.     INPUTS
  5688.     int fd;         file descriptor to read from
  5689.  
  5690.     void *buf;        pointer to buffer to read data into
  5691.  
  5692.     int len;        maximum number of bytes to read
  5693.  
  5694.     RESULTS
  5695.     int r;            number of bytes actually read (could be less than
  5696.                 len or 0), or < 0 if error.
  5697.  
  5698.     SEE ALSO
  5699.     close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  5700.     rmdir, unlink, write
  5701.  
  5702.     EXAMPLE
  5703.     #include <fcntl.h>
  5704.     #include <assert.h>
  5705.  
  5706.     main()
  5707.     {
  5708.        int fd;
  5709.        int r;
  5710.        char buf[32];
  5711.        fd = open("T:xx", O_WRONLY|O_CREAT|O_TRUNC);
  5712.        assert(fd >= 0);
  5713.        write(fd, "FuBar\n", 6);
  5714.        close(fd);
  5715.        fd = open("T:xx", O_RDONLY);
  5716.        assert(fd >= 0);
  5717.        r = read(fd, buf, sizeof(buf)); /* sizeof(buf)==32 */
  5718.        close(fd);
  5719.        assert(r == 6);
  5720.        /*
  5721.         *  note that the buffer is not terminated with
  5722.         *  a NULL, but since we are using write() which
  5723.         *  requires a length it does not matter
  5724.         */
  5725.        write(1, buf, r);
  5726.     }
  5727.  
  5728. dice/realloc                                                    dice/realloc
  5729.  
  5730.     FUNCTION
  5731.     reallocate memory allocated by calloc, malloc, or strdup (ANSI)
  5732.  
  5733.     SYNTAX
  5734.     #include <stdlib.h>
  5735.     void *newptr = realloc(oldptr, bytes)
  5736.     void *oldptr;
  5737.     size_t bytes;
  5738.  
  5739.     DESCRIPTION
  5740.     realloc reallocates a previously allocated buffer, making it larger
  5741.     or smaller.  It returns a pointer to a new buffer which might be the
  5742.     same as the old buffer, but might not.    Data in the original buffer
  5743.     is copied to the new buffer and the original buffer is freed.  When
  5744.     extending a buffer with realloc note that the extended bytes (beyond
  5745.     the original buffer) will come up garbage.  You may pass a NULL as
  5746.     the first argument to realloc which basically makes realloc a malloc.
  5747.  
  5748.     INPUTS
  5749.     void *oldptr;        pointer to original allocated buffer
  5750.  
  5751.     size_t bytes;        size of new buffer
  5752.  
  5753.     RESULTS
  5754.     void *newptr;        pointer to new buffer
  5755.  
  5756.     SEE ALSO
  5757.     malloc, calloc, strdup
  5758.  
  5759.     EXAMPLE
  5760.     #include <string.h>
  5761.     #include <assert.h>
  5762.     #include <stdlib.h>
  5763.     main()
  5764.     {
  5765.        char *s;
  5766.        int len;
  5767.        s = strdup("This is a test");
  5768.        assert(s);
  5769.        len = strlen(s);
  5770.        /*
  5771.         *  Remember that len does not include the NULL
  5772.         *  byte at the end of the string
  5773.         */
  5774.        s = realloc(s, len + 8);   /*  make more room */
  5775.        assert(s);
  5776.        /*
  5777.         *  we can use strcat since in extending the
  5778.         *  allocated string the NULL *was* copied along
  5779.         *  with the string during the realloc.
  5780.         */
  5781.        strcat(s, "xx");
  5782.        puts(s);       /*  This is a testxx    */
  5783.        return(0);
  5784.     }
  5785.  
  5786. dice/rega4                                                        dice/rega4
  5787.  
  5788.     FUNCTION
  5789.     return current contents of register A4 (DICE)
  5790.  
  5791.     SYNTAX
  5792.     char *basePtr = rega4();
  5793.  
  5794.     DESCRIPTION
  5795.     rega4 is not geta4;  rega4 simply returns the current contents of the
  5796.     A4 register when you need it.  Note that DICE offsets the A4 register
  5797.     32766 from the actual small-data base so as to be able to use the
  5798.     entire -32768 to 32767 range to access 64 kilobytes of small-data.
  5799.     Note that a rega4 call inside a subroutine qualified with __geta4 is
  5800.     guaranteed to return the data base pointer.  Also, a rega4 call from
  5801.     any subroutine not called from an interrupt or a call back will
  5802.     return the proper data base pointer.
  5803.  
  5804.     ## WARNING: Programs which use this function will not be able to be
  5805.     ## made resident.
  5806.  
  5807. dice/remove                                                      dice/remove
  5808.  
  5809.     FUNCTION
  5810.     delete a file (ANSI)
  5811.  
  5812.     SYNTAX
  5813.     #include <stdio.h>
  5814.     int error = remove(filename);
  5815.     const char *filename;
  5816.  
  5817.     DESCRIPTION
  5818.     remove deletes the specified file path returning 0 on success, a
  5819.     negative number on failure.  On the Amiga, an error will occur if you
  5820.     try to delete a file currently opened by yourself or any other
  5821.     process.  remove is an ANSI function.  unlink does the same thing but
  5822.     is a UNIX-compatible function.
  5823.  
  5824.     INPUTS
  5825.     char *filename;     filename to delete
  5826.  
  5827.     RESULTS
  5828.     int error;        0 on success, a negative number on failure
  5829.  
  5830.     SEE ALSO
  5831.     unlink
  5832.  
  5833.     EXAMPLE
  5834.     #include <stdio.h>
  5835.     main()
  5836.     {
  5837.        int error = remove("T:XXX");
  5838.        if (error < 0)
  5839.        {
  5840.           perror("remove(\"T:XXX\") failed");
  5841.           exit(1);
  5842.        }
  5843.        puts("T:XXX has been deleted");
  5844.        return(0);
  5845.     }
  5846.  
  5847. dice/rename                                                      dice/rename
  5848.  
  5849.     FUNCTION
  5850.     rename a file, or move a file from one directory to another on the
  5851.     same filesystem (ANSI)
  5852.  
  5853.     SYNTAX
  5854.     #include <stdio.h>
  5855.     int error = rename(origname, newname);
  5856.     const char *origname;
  5857.     const char *newname;
  5858.  
  5859.     DESCRIPTION
  5860.     rename renames a file.    You may also use rename to move a file (and
  5861.     rename at the same time) to another directory on the same filesystem.
  5862.     rename returns 0 on success, a negative number on failure.
  5863.  
  5864.     INPUTS
  5865.     const char *origname;
  5866.                 existing file const char
  5867.  
  5868.     *newname;        new filename and/or path
  5869.  
  5870.     RESULTS
  5871.     int error;        0 on success, a negative number on failure
  5872.  
  5873.     SEE ALSO
  5874.     rewind
  5875.  
  5876.     EXAMPLE
  5877.     /*
  5878.      *  create the file T:xxjunk and the directory
  5879.      *  T:junkdir then move T:xxjunk into T:junkdir
  5880.      *  and rename to T:yyjunk at the same time.
  5881.      *  As is aptly demonstrated by this example, some
  5882.      *  errors are not really errors.  For example,
  5883.      *  mkdir where the dir already exists is not usually
  5884.      *  an error.
  5885.      */
  5886.     #include <stdio.h>
  5887.     #include <assert.h>
  5888.     #include <errno.h>
  5889.     main()
  5890.     {
  5891.         FILE *fp;     int error;
  5892.         error = mkdir("T:junkdir");
  5893.         if (error < 0 && errno != EEXIST)
  5894.         perror("mkdir");
  5895.         fp = fopen("T:xxjunk", "w");
  5896.         if (fp == NULL) {
  5897.         perror("fopen"); exit(1);
  5898.         }
  5899.         fprintf(fp, "This was originally T:xxjunk!\n");
  5900.         fclose(fp);
  5901.  
  5902.         error = rename("T:xxjunk", "T:junkdir/yyjunk");
  5903.         if (error < 0)
  5904.            perror("Error renaming T:xxjunk");
  5905.         else
  5906.            puts("rename succeeded, look in T:junkdir");
  5907.         return(0);
  5908.     }
  5909.  
  5910. dice/rewind                                                      dice/rewind
  5911.  
  5912.     FUNCTION
  5913.     seek filepointer to beginning of file (ANSI)
  5914.  
  5915.     SYNTAX
  5916.     #include <stdio.h>
  5917.     void rewind(fp);
  5918.     FILE *fp;
  5919.  
  5920.     DESCRIPTION
  5921.     rewind rewinds the file to the beginning, equivalent to fseek(fp, 0L,
  5922.     0);.
  5923.  
  5924.     || NOTE: Refer to the file_pointer manual page for general
  5925.     || information.
  5926.  
  5927.     INPUTS
  5928.     FILE *fp;        file pointer to rewind
  5929.  
  5930.     SEE ALSO
  5931.     fseek, fgetpos, fsetpos
  5932.  
  5933.     EXAMPLE
  5934.     /* print a file 3 times */
  5935.     #include <stdio.h>
  5936.     main(int ac, char**av) {
  5937.        FILE *fp;
  5938.        int i;
  5939.        char buf[256];
  5940.        if (ac == 1) {
  5941.           puts("Expected textfile argument");
  5942.           exit(1);
  5943.        }
  5944.        fp = fopen(av[1], "r");
  5945.        if (fp == NULL) {
  5946.           printf("Unable to open %s\n", av[1]);
  5947.           exit(1);
  5948.        }
  5949.        for (i = 1; i <= 3; ++i) {
  5950.           rewind(fp); printf("PRINTING #%d\n", i);
  5951.           while (fgets(buf, sizeof(buf), fp))
  5952.          fputs(buf, stdout);
  5953.        }
  5954.        return(0);
  5955.     }
  5956.  
  5957. dice/rmdir                                                        dice/rmdir
  5958.  
  5959.     FUNCTION
  5960.     delete a directory (UNIX)
  5961.  
  5962.     SYNTAX
  5963.     #include <stdio.h>
  5964.     int r = rmdir(dirname);
  5965.     char *dirname;
  5966.  
  5967.     DESCRIPTION
  5968.     rmdir deletes a directory.  The directory must be empty for the
  5969.     deletion to work.  On the Amiga this call is equivalent to remove or
  5970.     unlink.
  5971.  
  5972.     INPUTS
  5973.     char *dirname;        name of directory to delete
  5974.  
  5975.     RESULTS
  5976.     int r;            0 if successful, non-zero if error
  5977.  
  5978.     SEE ALSO
  5979.     mkdir
  5980.  
  5981.     EXAMPLE
  5982.     #include <assert.h>
  5983.     main()
  5984.     {
  5985.        int r;
  5986.        r = mkdir("T:tmpdir");
  5987.        assert(r == 0);
  5988.        r = rmdir("T:tmpdir");
  5989.        assert(r == 0);
  5990.     }
  5991.  
  5992. dice/scanf,fscanf,sscanf                            dice/scanf,fscanf,sscanf
  5993.  
  5994.     FUNCTION
  5995.     scan formatted text and convert to variables (ANSI)
  5996.  
  5997.     SYNTAX
  5998.     #include <stdio.h>
  5999.     int n = scanf(ctl, ...);      /* Input: standard in */
  6000.     int n = fscanf(fp, ctl, ...); /* Input: file pointer */
  6001.     int n = sscanf(str,ctl, ...); /* Input: string buffer */
  6002.     const char *ctl;
  6003.     FILE *fp;
  6004.     char *str;
  6005.  
  6006.     DESCRIPTION
  6007.     These functions scan the specified input file or buffer for fields
  6008.     matching those specified by the control field. Commands starting with
  6009.     % relate the scanned text to a list of pointers. The values the
  6010.     pointers point to are updated (say that three times fast). Other
  6011.     characters in the control field must match the scanned text exactly,
  6012.     except for white space characters, which match any length of white
  6013.     space in the scanned text.
  6014.  
  6015.     Control Field Commands
  6016.     ----------------------
  6017.     The control field command format is as follows:
  6018.  
  6019.         %[*][nnn][h/l/L]<conversion-specifier>
  6020.  
  6021.      %  All conversion specifiers start with %.  Use %% to match a single
  6022.         % in the source text.
  6023.  
  6024.      *  An optional * tells scanf to perform the conversion, but discard
  6025.         the result. Do not include a destination pointer for skiped
  6026.         conversions.
  6027.  
  6028.        nnn  An optional decimal number is used for string conversion to
  6029.         specify a maximum field width.
  6030.  
  6031.      h  The modifier h specifies the destination should be treated as a
  6032.         short integer rather, than an integer.  The h conversion applies
  6033.         to d, i, n, o, u, x and X.
  6034.  
  6035.      l  The modifier l specifies the destination should be treated as a
  6036.         long integer, rather than an integer.  The l conversion applies
  6037.         to d, i, o, u, x and X.
  6038.  
  6039.      L  When used with formats e, f or g, specifies the destination
  6040.         should be treated to a long double rather than a double.
  6041.  
  6042.     Conversion Specifiers
  6043.     ---------------------
  6044.      c  With no field width specified, converts one character.  With a
  6045.         field width, converts the number of characters specified by the
  6046.         field width into an array. The expected argument is a pointer to
  6047.         a character or array of characters. No white space is skipped.
  6048.  
  6049.      d  Converts a decimal (base 10) number.  The expected argument is a
  6050.         pointer to an integer.  The l and h modifiers may be used to
  6051.         specify either a long or short integer result.
  6052.  
  6053.      e/f/g  Scans a floating point number.  If the l modifier is used, a long
  6054.         double pointer is expected (not implemented in DICE yet), else a
  6055.         double is expected.
  6056.  
  6057.      i  Converts a number to an integer.  The format should be equivalent
  6058.         to that expected by strtol with a base argument of 0 (automatic
  6059.         detection of format).
  6060.  
  6061.      n  This command does not scan any text.  It places into an integer
  6062.         the current count of processed characters.
  6063.  
  6064.      o  An octal number is expected.  The value is stored to an integer.
  6065.  
  6066.      p  A pointer is expected, in the same format as the %p from printf.
  6067.         The value is stored into a pointer, passed as void ** (a pointer
  6068.         to any type of pointer).
  6069.  
  6070.      s  Reads a string of non-white space characters and copies into the
  6071.         array specified by the argument.  The argument must be of type
  6072.         char * and have enough space to handle any possible string plus a
  6073.         NULL terminator.
  6074.  
  6075.      x  A hexadecimal (base 16) number is expected.  The value is stored
  6076.         into an integer.  This is equivalent to calling strtol with a
  6077.         base of 16.
  6078.  
  6079.     %%  Match a single % in the input stream.
  6080.  
  6081.      [...]  Scan a scanset.  Scan the input stream and place the characters
  6082.         into a char * buffer until a character is read that does not
  6083.         match the scanset.    If a scan set begins with ^ (as in [^abcd])
  6084.         then all characters are allowed except those specified in the
  6085.         scanset.  If a scanset begins as []abcd] or [^]abcd] then the ']'
  6086.         character is included in the scan set and the set is terminated
  6087.         by ']'.
  6088.  
  6089.         || NOTE: All scanf arguments are pointers.    A common mistake is
  6090.         || to pass arguments directly; pointers are required.  All
  6091.         || floating point arguments must be pointers to doubles.
  6092.  
  6093.     INPUTS
  6094.     char *ctl;        format control string, containing % commands
  6095.  
  6096.     FILE *fp;        file pointer for fscanf
  6097.  
  6098.     char *str;        string pointer for sscanf
  6099.  
  6100.     ...            pointers to variables ready to receive
  6101.                 conversions.
  6102.  
  6103.     RESULTS
  6104.     int n;            Number of conversions that occurred or -1 if no
  6105.                 conversions could be made (this usually means
  6106.                 EOF).  The function may return less than the
  6107.                 number of requested conversions.  This value does
  6108.                 not count any %* conversions.
  6109.  
  6110.     SEE ALSO
  6111.     sprintf, printf, fprintf, strtol
  6112.  
  6113.     EXAMPLE
  6114.     #include <stdio.h>
  6115.     main(int ac, char**av)
  6116.     {
  6117.     int    n, integer;
  6118.  
  6119.        n = sscanf("Input: 132\n", "Input: %ld\n", &integer);
  6120.        printf("First test: n=%d integer=%d  ", n, integer);
  6121.  
  6122.     short a[3] = {-1, -2, -3}; // Unscanned arguments are NOT
  6123.     int   b[3] = {-4, -5, -6}; // cleared - they retain
  6124.     char  buf1[11], buf2[11];  // former values!
  6125.  
  6126.        buf1[0]=buf2[0]=buf2[10] = 0;
  6127.  
  6128.        if (ac != 2) {
  6129.           puts("Expected string to format!"); exit(1);
  6130.        }
  6131.        n = sscanf(av[1],"%hd %ho %hi %*d %X %n%10s %10c   -%d-",
  6132.                  a+0,a+1,a+2,   b+0,b+1,buf1,buf2,b+2);
  6133.        printf("Second test: %d elements\n", n);
  6134.        printf("a (shorts): %d %d %d\n", a[0], a[1], a[2]);
  6135.        printf("b (ints)  : %d %d %d\n", b[0], b[1], b[2]);
  6136.        printf("buf1      : %s\nbuf2      : %s\n", buf1, buf2);
  6137.        return(0);
  6138.     }
  6139.     /* scanf "100 100 0x100 200 0x300 reduce reuse recycle!"
  6140.     ** First test: n=1 integer=132    Second test: 6 elements
  6141.     ** a (shorts): 100 64 256
  6142.     ** b (ints)  : 768 24 -6
  6143.     ** buf1      : reduce
  6144.     ** buf2      : reuse recy
  6145.     */
  6146.  
  6147. dice/setbuf,setvbuf                                      dice/setbuf,setvbuf
  6148.  
  6149.     FUNCTION
  6150.     change a file pointer's buffering (ANSI)
  6151.  
  6152.     SYNTAX
  6153.     #include <stdio.h>
  6154.     void setbuf(fp, buf);
  6155.     error = setvbuf(fp, buf, mode, size);
  6156.     FILE *fp; char *buf;
  6157.     int mode; size_t size; int error;
  6158.  
  6159.     DESCRIPTION
  6160.     setbuf changes the internal buffer used by stdio.  The buffer you
  6161.     pass it must be BUFSIZ bytes in size.  You can set a file pointer to
  6162.     unbuffered by passing NULL for your buffer.
  6163.  
  6164.     setvbuf supersedes this call and is, in general, a better function.
  6165.     Type type argument must be one of _IOFBF (Fully Buffered), _IOLBF
  6166.     (Line Buffered) or _IONBF (Non Buffered).  For use with DICE it is
  6167.     best to supply a buffer size, but a NULL buf pointer. DICE will
  6168.     allocate buffers as they are needed.
  6169.  
  6170.     ## WARNING: If buffering is turned off for a file pointer
  6171.     ## representing a console device, the console device is set to
  6172.     ## unbuffered as well.    If buffering is turned on for a file pointer
  6173.     ## representing a console device, the console device is set to
  6174.     ## buffered as well.
  6175.  
  6176.     || NOTE: Refer to the file_pointer manual page for general
  6177.     || information.
  6178.  
  6179.     INPUTS
  6180.     FILE *fp;        file pointer to affect.
  6181.  
  6182.     char *buf;        buffer for use by the file pointer, or NULL.
  6183.  
  6184.     int type;        (setvbuf) type of buffering.
  6185.  
  6186.     size_t size;        (setvbuf) requested buffer size or zero.
  6187.  
  6188.     int error;        (setvbuf) error code (if size or type are
  6189.                 invalid).
  6190.  
  6191.     EXAMPLE 1
  6192.     #include <stdio.h>
  6193.     main()
  6194.     {
  6195.     FILE *fp;
  6196.  
  6197.        fp = fopen("CON:0/0/640/100/DICE Setbuf Test","w");
  6198.        if(! fp )
  6199.           exit( 10 );
  6200.  
  6201.        fprintf(fp, "This will be buffered, ");
  6202.        sleep(2);
  6203.        setvbuf(fp, NULL, _IONBF, 0);
  6204.        fprintf(fp, "yet these will print immediately ");
  6205.        sleep(2);
  6206.        fprintf(fp, "(we are unbuffered).");
  6207.        sleep(4);
  6208.        fprintf(fp, "\n");
  6209.  
  6210.        setvbuf(fp, NULL, _IOLBF, 128);
  6211.        fprintf(fp, "Now back to buffered... ");
  6212.        sleep(2);
  6213.        fprintf(fp, "(See - you had to wait).\n");
  6214.        sleep(8);
  6215.  
  6216.        fclose( fp );
  6217.        return(0);
  6218.     }
  6219.  
  6220.     EXAMPLE 2
  6221.     #include <stdio.h>
  6222.     #define BUFFER_SIZE 128
  6223.     main()
  6224.     {
  6225.        int c;    char buf[256];
  6226.  
  6227.        setvbuf(stdin, NULL, _IONBF, 0);
  6228.        printf("Type a character: ");
  6229.        fflush(stdout);
  6230.        c = getchar();
  6231.        printf("c = %d\n", c);
  6232.  
  6233.        setvbuf(stdin, NULL, _IOLBF, BUFFER_SIZE);
  6234.        printf("Type a line: ");
  6235.        fflush(stdout);
  6236.        fgets(buf, sizeof(buf), stdin);
  6237.        printf("You said   : %s\n", buf);
  6238.        return(0);
  6239.     }
  6240.  
  6241. dice/setjmp,longjmp                                      dice/setjmp,longjmp
  6242.  
  6243.     FUNCTION
  6244.     setjmp: save procedure context for future long jump (ANSI)
  6245.     longjmp: jump to a previously saved procedure context (ANSI)
  6246.  
  6247.     SYNTAX
  6248.     #include <setjmp.h>
  6249.     int r = setjmp(enviro);
  6250.     (void) longjmp(enviro, rval)
  6251.     jmp_buf enviro;
  6252.     int rval;
  6253.  
  6254.     DESCRIPTION
  6255.     First, setjmp stores the current procedure context into an
  6256.     environment array whose type is jmp_buf.  When called by a procedure
  6257.     it saves the environment and returns 0.  Then when called, longjmp
  6258.     jumps to a previously saved environment causing execution to begin at
  6259.     the setjmp call that saved that environment. Yet instead of returning
  6260.     0 the 'resumed' setjmp returns a return value set by the longjmp
  6261.     call.  Jmp_buf is a typedef of an array, thus by passing a jmp_buf
  6262.     structure we really pass the address of it.  setjmp and longjmp are
  6263.     fully compatible with dynamic stacks  (-gs option to DCC).
  6264.  
  6265.     :: Beginner's Note: setjmp and longjmp should be used sparingly, if
  6266.     :: at all. They make code hard to understand, are rife with potential
  6267.     :: for adding bugs and are considered even uglier than the C goto
  6268.     :: statement.
  6269.  
  6270.     In the example below main is still stacked when the longjmp occurs
  6271.     and is thus valid.  It would be illegal, for instance, to call a
  6272.     subroutine which does a setjmp and RETURNS to you, then longjmp back
  6273.     to that subroutine. The contents of the jmp_buf structure are private
  6274.     and may not be modified by the program.
  6275.  
  6276.     ## WARNING: You can only longjmp to a previously saved environment
  6277.     ## that has not been unstacked.  WARNING: setjmp saves the current
  6278.     ## state of the registers, but not any registers that get modified
  6279.     ## between the setjmp and the longjmp!
  6280.  
  6281.     Thus, auto variables placed in registers (which is done so
  6282.     automatically under DICE) may contain 'old' values after a longjmp if
  6283.     they were modified after the setjmp. To prevent this such variables
  6284.     must, by ANSI convention, be made volatile.  The volatile qualifier
  6285.     forces an auto variable to be placed on the stack instead of in a
  6286.     register.
  6287.  
  6288.     INPUTS
  6289.     jmp_buf enviro;     environment structure
  6290.  
  6291.     int rval;        return value (longjmp call)
  6292.  
  6293.     RESULTS
  6294.     (setjmp) int r;     0 when called directly, rval when environment
  6295.                 restored by a longjmp
  6296.  
  6297.     SEE ALSO
  6298.     onbreak, signal
  6299.  
  6300.     EXAMPLE
  6301.     #include <stdio.h>
  6302.     #include <setjmp.h>
  6303.     jmp_buf x;
  6304.  
  6305.     int  brk(void);
  6306.     void breakme(void);
  6307.  
  6308.     main()
  6309.     {
  6310.        int r;
  6311.        onbreak(brk);
  6312.  
  6313.        r = setjmp(x); // returns 0 when called by main
  6314.        puts("\nArnie sez:  I'll be back...");
  6315.  
  6316.        if (r == 0)
  6317.           for (;;)
  6318.         breakme();
  6319.  
  6320.        printf("Broke and jumped, r = %d\n", r);
  6321.        return(0);
  6322.     }
  6323.     /* even though the onbreak call is supposed to return,
  6324.     ** we can longjmp out of it as well.
  6325.     */
  6326.     int brk()
  6327.     {
  6328.        longjmp(x, 23);
  6329.     }
  6330.     void breakme()
  6331.     {
  6332.        puts("Break Me With ^C!");
  6333.     }
  6334.  
  6335. dice/signal                                                      dice/signal
  6336.  
  6337.     FUNCTION
  6338.     set a signal vector for a signal (ANSI)
  6339.  
  6340.     SYNTAX
  6341.     #include <signal.h>
  6342.     typedef void (*__sigfunc)(int);
  6343.     __sigfunc oldfunc = signal(signo, newfunc)
  6344.     int signo;
  6345.     __sigfunc newfunc;
  6346.  
  6347.     DESCRIPTION
  6348.     signal sets a signal vector function for a given signal number as
  6349.     defined in <signal.h> and returns the previously set function.
  6350.     Currently only SIGINT causes any semi-asynchronous action to occur.
  6351.     You may pass newfunc as your own signal function or one of:
  6352.  
  6353.    SIG_ERR  error (exit program)
  6354.  
  6355.    SIG_DFL  default (for break, normal operation)
  6356.  
  6357.    SIG_IGN  ignore signal (for break, ^C is now ignored)
  6358.  
  6359.         when a signal occurs, the signal is set back to its default
  6360.         condition before the handler is called.  Thus, if you are
  6361.         allowing multiple signals to occur you must restore the signal
  6362.         vector with signal from your signal handler before it returns.
  6363.  
  6364.         || NOTE: On the Amiga, signals are not truly asynchronous.    ^C is
  6365.         || detected during stdio calls only.  No other signal is
  6366.         || implemented though you CAN modify any signal vector 0 to 31
  6367.         || and raise it with the raise call. Early versions of DICE,
  6368.         || including quite possibly this version, do not understand
  6369.         || complex type declarations containing procedural types. Thus,
  6370.         || you may have to get around the problem by building up a
  6371.         || complex procedural type with typedefs.  Unlike onbreak, a
  6372.         || signal function returns no value.
  6373.  
  6374.     INPUTS
  6375.     int signo;        signal to modify, usually SIGINT __sigfunc
  6376.  
  6377.     newfunc;        signal function or SIG_ERR, SIG_DFL, SIG_IGN
  6378.  
  6379.     RESULTS
  6380.     __sigfunc oldfunc;
  6381.                 previous signal function
  6382.  
  6383.     SEE ALSO
  6384.     raise
  6385.  
  6386.     EXAMPLE
  6387.     #include <signal.h>
  6388.     void brkfunc(int);
  6389.     main()
  6390.     {
  6391.        short i;
  6392.        puts("The following is unbreakable");
  6393.        sleep(1);
  6394.        signal(SIGINT, SIG_IGN);
  6395.        for (i = 0; i < 100; ++i) printf("1 %d\n", i);
  6396.        puts("The following may be broken out of");
  6397.        puts("with a cute message");
  6398.        sleep(1);
  6399.        signal(SIGINT, brkfunc);
  6400.        for (i = 0; i < 100; ++i) printf("2 %d\n", i);
  6401.        puts("The following may be broken out of");
  6402.        sleep(1);
  6403.        signal(SIGINT, SIG_DFL);
  6404.        for (i = 0; i < 100; ++i) printf("3 %d\n", i);
  6405.        puts("Hey! You never hit ^C! \
  6406.          What kind of test is this!");
  6407.        return(0);
  6408.     }
  6409.     void brkfunc(int signo)
  6410.     {
  6411.        printf("signo %d. Want cute?  Get a kitten.\n", signo);
  6412.        exit(1);
  6413.     }
  6414.  
  6415. dice/sin,fsin                                                  dice/sin,fsin
  6416.  
  6417.     FUNCTION
  6418.     sin: return sine of a double quantity (ANSI)
  6419.     fsin: return sine of a float quantity (ANSI)
  6420.  
  6421.     LIBRARY
  6422.     m.lib
  6423.  
  6424.     SYNTAX
  6425.     #include <math.h>
  6426.     double a = sin(b);
  6427.     double b;
  6428.     float  c = fsin(d);
  6429.     float  d;
  6430.  
  6431.     DESCRIPTION
  6432.     sin returns the sine of a double quantity; fsin returns the sine of a
  6433.     floating point quantity.  These functions use radian measure ("rad"
  6434.     on your calculator).
  6435.  
  6436.     INPUTS
  6437.     double b;        double floating point value
  6438.  
  6439.     float d;        float floating point value
  6440.  
  6441.     RESULTS
  6442.     double a;        result double floating point value
  6443.  
  6444.     float c;        result float floating point value
  6445.  
  6446.     SEE ALSO
  6447.     acos, asin, atan, cos, exp, fabs, log, log10, pow, sqrt, tan, facos,
  6448.     fasin
  6449.  
  6450.     EXAMPLE
  6451.     See cos for an example.
  6452.  
  6453. dice/sleep                                                        dice/sleep
  6454.  
  6455.     FUNCTION
  6456.     sleep for a period of time (UNIX)
  6457.  
  6458.     SYNTAX
  6459.     #include <stdio.h>
  6460.     sleep(n);
  6461.     int n;
  6462.  
  6463.     DESCRIPTION
  6464.     The sleep function waits for a period of time specified in seconds.
  6465.     It can be interrupted by a ^C.
  6466.  
  6467.     || NOTE: The timekeeping of sleep is not very accurate.  On the
  6468.     || Amiga, sleep is implemented with a loop of delay(50); calls.
  6469.  
  6470.     INPUTS
  6471.     int n;            number of seconds to sleep
  6472.  
  6473.     EXAMPLE
  6474.     #include <stdio.h>
  6475.     main(int ac, char**av)
  6476.     {
  6477.        puts("Sleeping for 10 seconds");
  6478.        sleep(10);
  6479.        puts("That was a good rest");
  6480.        return(0);
  6481.     }
  6482.  
  6483. dice/sqrt,fsqrt                                              dice/sqrt,fsqrt
  6484.  
  6485.     FUNCTION
  6486.     sqrt: return the square root of a double (ANSI)
  6487.     fsqrt: return the square root of a float (ANSI)
  6488.  
  6489.     LIBRARY
  6490.     m.lib
  6491.  
  6492.     SYNTAX
  6493.     #include <math.h>
  6494.     double a = sqrt(b);
  6495.     double b;
  6496.     float  c = fsqrt(d);
  6497.     float  d;
  6498.  
  6499.     DESCRIPTION
  6500.     sqrt returns the square root of a double quantity; fsqrt returns the
  6501.     square root of a floating point quantity.
  6502.  
  6503.     INPUTS
  6504.     double b;        double floating point value
  6505.  
  6506.     float d;        float floating point value
  6507.  
  6508.     RESULTS
  6509.     double a;        double floating point value
  6510.  
  6511.     float c;        float floating point value
  6512.  
  6513.     SEE ALSO
  6514.     acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, tan, facos,
  6515.     fasin
  6516.  
  6517.     EXAMPLE
  6518.     /*
  6519.      *  compile with the math library -lm
  6520.      */
  6521.     #include <math.h>
  6522.     #include <stdio.h>
  6523.     main()
  6524.  
  6525.     {
  6526.        {
  6527.           double a = sqrt(0.25);
  6528.           printf("sqrt 0.25 = %lf\n", a);
  6529.           /* 0.5000 */
  6530.        }
  6531.        {  /*  less accuracy  */
  6532.           float a = fsqrt(0.25);
  6533.           printf("sqrt 0.25 = %lf\n", (double)a);
  6534.        }
  6535.        return(0);
  6536.     }
  6537.  
  6538. dice/srand                                                        dice/srand
  6539.  
  6540.     FUNCTION
  6541.     set seed for pseudo-random number (ANSI)
  6542.  
  6543.     SYNTAX
  6544.     #include <stdio.h>
  6545.     #include <stdlib.h>
  6546.     (void) srand(seed)
  6547.     unsigned int seed;
  6548.  
  6549.     DESCRIPTION
  6550.     srand initializes the seed for function rand.
  6551.  
  6552.     INPUTS
  6553.     unsigned int seed;
  6554.                 an unsigned integer used to seed the
  6555.                 pseudo-random number generator via srand.
  6556.  
  6557.     SEE ALSO
  6558.     rand
  6559.  
  6560.     EXAMPLE
  6561.     See the "rand" manual page for an example
  6562.  
  6563. dice/stack_abort                                            dice/stack_abort
  6564.  
  6565.     FUNCTION
  6566.     exit point when dynamic stack allocation fails (DICE)
  6567.  
  6568.     SYNTAX
  6569.     void stack_abort(void)
  6570.     {
  6571.         /* .. your exit code .. */
  6572.         abort();
  6573.     }
  6574.  
  6575.     DESCRIPTION
  6576.     When dynamic stack allocation is enabled via the -gs option and such
  6577.     an allocation fails, stack_abort is called.  If you do not specify a
  6578.     stack_abort routine, the c.lib stack_abort function will simply call
  6579.     abort.
  6580.  
  6581.     If you do specify a stack_abort routine, you have two choices: you
  6582.     can exit out of the program, or you can simply return from the
  6583.     subroutine which retries the allocation and calls stack_abort again
  6584.     if it fails (perhaps wait a bit in hopes memory has become
  6585.     available).
  6586.  
  6587.     The program has about 2KB of stack left at the time this function is
  6588.     called.  Since a low memory condition exists when this function is
  6589.     called you should not do anything that might require additional
  6590.     allocations!
  6591.  
  6592.     SEE ALSO
  6593.     abort, exit
  6594.  
  6595. dice/stat                                                          dice/stat
  6596.  
  6597.     FUNCTION
  6598.     stat a file by name (UNIX)
  6599.  
  6600.     SYNTAX
  6601.     #include <sys/stat.h>
  6602.     int error = stat(name, &stat_buf);
  6603.     const char *name;
  6604.     struct stat stat_buf;
  6605.  
  6606.     DESCRIPTION
  6607.     stat is a UNIX-compatible call that returns information pertaining to
  6608.     the file represented by its name. If 0 is returned, stat succeeded
  6609.     and the fields will be filled in as follows:
  6610.  
  6611.    st_mode  Flags S_IFDIR if directory, S_IFREG if regular file, S_IREAD if
  6612.         readable, S_IWRITE if writable, S_IEXEC if executable.
  6613.  
  6614.    st_size  Size of the file, in bytes.
  6615.  
  6616.  st_blksize
  6617.         Always returns 512 (for now).
  6618.  
  6619.  st_blocks  A guess at the number of actual blocks the file takes up,
  6620.         including headers and side sectors.
  6621.  
  6622.   st_ctime  Time the file was last modified.
  6623.  
  6624.   st_mtime  Same as st_ctime.
  6625.  
  6626.     st_dev  Physical device ID (do not try to interpret this field, but it
  6627.         does represent the DOS handler).
  6628.  
  6629.     st_ino  inode ID (usually a file block number on the Amiga).
  6630.  
  6631.         || NOTE: On the Amiga one normally cannot directly examine a file
  6632.         || that is exclusively locked.  If this case occurs, stat will
  6633.         || attempt to scan the parent directory for the file and if that
  6634.         || doesn't work, returns -1.
  6635.  
  6636.     INPUTS
  6637.     char *name;        name of file to stat
  6638.  
  6639.     struct stat *sbuf;
  6640.                 address of stat structure that will be filled in
  6641.  
  6642.     RESULTS
  6643.     int error;        0 on success, < 0 on error
  6644.  
  6645.     SEE ALSO
  6646.     chdir
  6647.  
  6648.     EXAMPLE
  6649.     #include <stdio.h>
  6650.     #include <fcntl.h>
  6651.     #include <sys/stat.h>
  6652.     main(int ac, char**av)
  6653.     {
  6654.        int r;
  6655.        struct stat stat_buf;
  6656.        if (ac == 1) {
  6657.           puts("Expected a test file name");
  6658.           exit(1);
  6659.        }
  6660.        r = stat(av[1], &stat_buf);
  6661.        if (r < 0)
  6662.           printf("Can't stat %s\n", av[1]);
  6663.        else {
  6664.           printf("File is %d bytes long\n", stat_buf.st_size);
  6665.           printf("modified %s", ctime(&stat_buf.st_ctime));
  6666.        }
  6667.        return(0);
  6668.     }
  6669.  
  6670. dice/stdin,stdout,stderr,EOF                    dice/stdin,stdout,stderr,EOF
  6671.  
  6672.     FUNCTION
  6673.     stdin: standard input channel (file pointer - MACRO)
  6674.     stdout: standard output channel (file pointer - MACRO)
  6675.     stderr: standard error channel (file pointer - MACRO)
  6676.     EOF: special value representing End-Of-File
  6677.  
  6678.     SYNTAX
  6679.     #include <stdio.h>
  6680.  
  6681.     DESCRIPTION
  6682.     stdin is the name for the program's standard input stream, a "FILE *"
  6683.     (Pointer to structure FILE).  This can be redirected via command line
  6684.     redirection when the program is run.  stdout is a FILE * type that
  6685.     represents the program's standard output stream.  This can also be
  6686.     redirected via command line redirection when the program is run.
  6687.     stderr is a FILE * type that represents the program's standard error
  6688.     stream. Currently stderr is opened by _main and represents the
  6689.     console device associated with the program regardless of standard
  6690.     redirections.  EOF is special value, -1 in this implementation, that
  6691.     represents an end of file marker.  Functions that return a single
  6692.     character actually return type int to allow EOF to be distinct from
  6693.     valid characters. Include the file stdio.h to use these definitions.
  6694.  
  6695.     These file pointers may be fclose'd or freopen'd at any time. The
  6696.     stdio macros getchar and putchar and stdio library routines gets and
  6697.     puts deal with stdin and stdout respectively while other library
  6698.     routines such as perror output to stderr.
  6699.  
  6700. dice/stpchr                                                      dice/stpchr
  6701.  
  6702.     FUNCTION
  6703.     Search for a character in a string (UNIX)
  6704.  
  6705.     SYNTAX
  6706.     #include <string.h>
  6707.     char *ptr = stpchr(s, c)
  6708.     const char *s;
  6709.     int c;
  6710.  
  6711.     DESCRIPTION
  6712.     This searches for the character c within the string pointed to by s.
  6713.     The terminating NULL at the end of s is NOT included in the search.
  6714.     A pointer to the first occurrence of c in s is returned or NULL if c
  6715.     could not be found. c is converted to a char by stpchr before
  6716.     beginning the search.
  6717.  
  6718.     || NOTE: It is better to use the ANSI standard strchr and strrchr
  6719.     || functions.
  6720.  
  6721.     INPUTS
  6722.     char *s;        pointer to string to search
  6723.  
  6724.     int c;            character to search for
  6725.  
  6726.     RESULTS
  6727.     char *ptr;        pointer to the first occurrence of the character
  6728.                 c in s, or NULL if c could not be found in s.
  6729.  
  6730.     SEE ALSO
  6731.     strchr, strrchr
  6732.  
  6733.     EXAMPLE
  6734.     #include <stdio.h>
  6735.     #include <string.h>
  6736.     #include <assert.h>
  6737.     main()
  6738.     {
  6739.        char *s = "this is a test";
  6740.        char *ptr;
  6741.        ptr = stpchr(s, 'i');
  6742.        assert(ptr == s + 2);
  6743.        puts(ptr);       /*  "is is a test"  */
  6744.        return(0);
  6745.     }
  6746.  
  6747. dice/stpcpy                                                      dice/stpcpy
  6748.  
  6749.     FUNCTION
  6750.     copy a string returning a pointer to the end of the destination
  6751.     (UNIX)
  6752.  
  6753.     SYNTAX
  6754.     #include <string.h>
  6755.     char *ptr = stpcpy(d, s);
  6756.     char *d;
  6757.     char *s;
  6758.  
  6759.     DESCRIPTION
  6760.     This function copies the NULL terminated string pointed to by s to
  6761.     the buffer d.  The NULL is copied.  A pointer to the NULL character
  6762.     at the end of the copied string in d is returned.
  6763.  
  6764.     || NOTE: stpcpy is non-standard.  While a stpcpy/stpcpy combination
  6765.     || is more efficient than a strcpy/strcat combination, strcpy and
  6766.     || strcat are standard functions and thus are guaranteed to exist in
  6767.     || all environments.
  6768.  
  6769.     INPUTS
  6770.     char *d;        pointer to beginning of destination buffer
  6771.  
  6772.     char *s;        pointer to beginning of source string
  6773.  
  6774.     RESULTS
  6775.     char *ptr;        pointer to end of data copied to destination
  6776.                 buffer
  6777.  
  6778.     SEE ALSO
  6779.     strcpy, strbpl
  6780.  
  6781.     EXAMPLE
  6782.     #include <stdio.h>
  6783.     #include <string.h>
  6784.     main()
  6785.     {
  6786.        char *buf1 = "Micky ";
  6787.        char *buf2 = "Moose";
  6788.        char dest[32];
  6789.        char *ptr;
  6790.        ptr = stpcpy(dest, buf1);
  6791.        stpcpy(ptr, buf2);
  6792.        puts(dest);       /* Micky Moose */
  6793.        return(0);
  6794.     }
  6795.  
  6796. dice/strbpl                                                      dice/strbpl
  6797.  
  6798.     FUNCTION
  6799.     unpack a string-array buffer into an array of pointers (DICE)
  6800.  
  6801.     SYNTAX
  6802.     #include <string.h>
  6803.     int num = strbpl(av, max, sary)
  6804.     char **av;
  6805.     int max;
  6806.     const char *sary;
  6807.  
  6808.     DESCRIPTION
  6809.     strbpl unpacks a string-array into an array of string pointers.  The
  6810.     string array is a series of NULL terminated strings strung together
  6811.     and terminated by a final NULL.  A pointer to each string is placed
  6812.     in the array-of-pointers (av) with a final NULL entry assuming the
  6813.     number of strings does not exceed (max-1).
  6814.  
  6815.     INPUTS
  6816.     char **av;        pointer to a preallocated array of pointers
  6817.  
  6818.     int max;        the maximum number of entries in the above array
  6819.  
  6820.     char *sary;        pointer to a packed string.
  6821.  
  6822.     RESULTS
  6823.     int num;        number of pointers loaded into the av array not
  6824.                 including the final NULL.  If num == max then the
  6825.                 av array was not large enough to fit all the
  6826.                 strings or the final NULL.
  6827.  
  6828.     EXAMPLE
  6829.     #include <stdio.h>
  6830.     #include <string.h>
  6831.     #include <assert.h>
  6832.     main()
  6833.     {
  6834.        char *sary = "this\0is\0a\0test\0\0";
  6835.        char *av[16];
  6836.        int n;
  6837.        #define arysize(x) (sizeof(x)/sizeof((x)[0]))
  6838.        n = strbpl(av, arysize(av), sary);
  6839.        assert(n == 4);     /*  n == 4  */
  6840.        puts(av[0]);       /*  this    */
  6841.        puts(av[1]);       /*  is      */
  6842.        puts(av[2]);       /*  a       */
  6843.        puts(av[3]);       /*  test    */
  6844.        assert(av[4] == NULL); /*  av[4] == NULL   */
  6845.        return(0);
  6846.     }
  6847.  
  6848. dice/strcat                                                      dice/strcat
  6849.  
  6850.     FUNCTION
  6851.     concatenate a string to an existing string (ANSI)
  6852.  
  6853.     SYNTAX
  6854.     #include <string.h>
  6855.     char *d = strcat(d, s);
  6856.     char *d;
  6857.     const char *s;
  6858.  
  6859.     DESCRIPTION
  6860.     strcat scans the destination buffer for the NULL terminator and then
  6861.     appends the source string to the destination buffer (removing the
  6862.     NULL terminator and placing one at the end after the concatenation).
  6863.     A pointer to the beginning of the destination buffer is returned.
  6864.  
  6865.     INPUTS
  6866.     char *d;        pointer to destination buffer which already
  6867.                 contains a string (which could be just a \0).
  6868.  
  6869.     char *s;        pointer to the NULL terminated source string
  6870.  
  6871.     RESULTS
  6872.     char *d;        same as the first argument, a pointer to the
  6873.                 destination buffer.
  6874.  
  6875.     SEE ALSO
  6876.     strncpy, strcpy, strncat
  6877.  
  6878.     EXAMPLE
  6879.     #include <stdio.h>
  6880.     #include <string.h>
  6881.     main()
  6882.     {
  6883.        char dest[80];
  6884.        char *s1 = "I had an elegant proof also, ";
  6885.        char *s2 = "but the console window was too narrow...";
  6886.  
  6887.        strcpy(dest, s1);
  6888.        puts( strcat(dest, s2) ); /* returns its first arg */
  6889.     }
  6890.  
  6891. dice/strchr                                                      dice/strchr
  6892.  
  6893.     FUNCTION
  6894.     search for a character in a string (ANSI)
  6895.  
  6896.     SYNTAX
  6897.     #include <string.h>
  6898.     char *ptr = strchr(s, c)
  6899.     const char *s;
  6900.     int c;
  6901.  
  6902.     DESCRIPTION
  6903.     This searches for the character c within the string pointed to by s.
  6904.     The terminating NULL at the end of s is included in the search.  A
  6905.     pointer to the first occurrence of c in s is returned or NULL if c
  6906.     could not be found. C is converted to a char by strchr before
  6907.     beginning the search.
  6908.  
  6909.     || NOTE: While strchr(s, 0); may be used to find the end of the
  6910.     || string this is slow compared to using the construction: char *ptr
  6911.     || = s + strlen(s);  /*  ptr = end of string s */.
  6912.  
  6913.     INPUTS
  6914.     char *s;        pointer to the string to search
  6915.  
  6916.     int c;            character to search for.
  6917.  
  6918.     RESULTS
  6919.     char *ptr;        pointer to the first occurrence of character c in
  6920.                 s or NULL if c could not be found in s.
  6921.  
  6922.     SEE ALSO
  6923.     strrchr
  6924.  
  6925.     EXAMPLE
  6926.     #include <stdio.h>
  6927.     #include <string.h>
  6928.     #include <assert.h>
  6929.     main()
  6930.     {
  6931.        char *s = "We feel incredibly agile";
  6932.        char *ptr;
  6933.        ptr = strchr(s, 'i');
  6934.        assert(ptr == s + 2);
  6935.        puts(ptr);       /* "incredibly agile" */
  6936.        return(0);
  6937.     }
  6938.  
  6939. dice/strcmp                                                      dice/strcmp
  6940.  
  6941.     FUNCTION
  6942.     compare two strings (ANSI)
  6943.  
  6944.     SYNTAX
  6945.     #include <string.h>
  6946.     int r = strcmp(s1, s2);
  6947.     const char *s1;
  6948.     const char *s2;
  6949.  
  6950.     DESCRIPTION
  6951.     strcmp compares two strings, returning -1 if s1 < s2,  0 if s1 == s2
  6952.     , and 1 if  s1 > s2.
  6953.  
  6954.     || NOTE: strcmp converts the chars in the string to unsigned
  6955.     || quantities when comparing them.  However, for portability you
  6956.     || should not strcmp strings containing negative characters (bit 7
  6957.     || set) for anything other than checking the result against 0.    Use
  6958.     || the memcmp routine instead.
  6959.  
  6960.     INPUTS
  6961.     char *s1;        pointer to first string
  6962.  
  6963.     char *s2;        pointer to second string
  6964.  
  6965.     RESULTS
  6966.     int r;            -1, 0, or 1.
  6967.  
  6968.     SEE ALSO
  6969.     strncmp, stricmp
  6970.  
  6971.     EXAMPLE
  6972.     #include <stdio.h>
  6973.     #include <string.h>
  6974.     #include <assert.h>
  6975.     main()
  6976.     {
  6977.        char *s1 = "abca";
  6978.        char *s2 = "abcd";
  6979.        char *s3 = "abcx";
  6980.        char *s4 = "abcdx";
  6981.        char *s5 = "abc";
  6982.        char *x2 = "abcd";
  6983.        int r;
  6984.        r = strcmp(s2, x2);
  6985.        /*  string s2 same as string x2 */
  6986.        assert(r == 0);
  6987.        r = strcmp(s2, s1);
  6988.        /*  string s2 larger than string s1*/
  6989.        assert(r > 0);
  6990.        r = strcmp(s2, s3);
  6991.        assert(r < 0);
  6992.        r = strcmp(s2, s4);
  6993.        assert(r < 0);
  6994.        r = strcmp(s2, s5);
  6995.        assert(r > 0);
  6996.        return(0);
  6997.     }
  6998.  
  6999. dice/strcpy                                                      dice/strcpy
  7000.  
  7001.     FUNCTION
  7002.     copy a string returning a pointer to the beginning of the destination
  7003.     (ANSI)
  7004.  
  7005.     SYNTAX
  7006.     #include <string.h>
  7007.     char *ptr = strcpy(d, s);
  7008.     char *d;
  7009.     char *s;
  7010.  
  7011.     DESCRIPTION
  7012.     strcpy copies the NULL terminated string pointed to by s to the
  7013.     buffer d.  The NULL is copied.    The first argument is returned (a
  7014.     pointer to the buffer d).
  7015.  
  7016.     INPUTS
  7017.     char *d;        pointer to beginning of destination buffer
  7018.  
  7019.     char *s;        pointer to beginning of source string
  7020.  
  7021.     RESULTS
  7022.     char *ptr;        same as the destination buffer pointer (d).
  7023.  
  7024.     SEE ALSO
  7025.     stpcpy
  7026.  
  7027.     EXAMPLE
  7028.     #include <stdio.h>
  7029.     #include <string.h>
  7030.     #include <assert.h>
  7031.     /*
  7032.      *  Note that the stpcpy() example accomplishes the same
  7033.      *  thing and is more efficient, but also requires the
  7034.      *  use of a temporary pointer as well as cluttering the
  7035.      *  source and being non-standard.
  7036.      *  strcpy()/strcat() is more portable, though less
  7037.      *  efficient.
  7038.      */
  7039.      main()
  7040.     {
  7041.        char *buf1 = "saber";
  7042.        char *buf2 = "tooth";
  7043.        char dest[32];
  7044.  
  7045.        strcpy(dest, buf1);
  7046.        strcat(dest, buf2);
  7047.        puts(dest);       /* sabertooth */
  7048.        return(0);
  7049.     }
  7050.  
  7051. dice/strcspn                                                    dice/strcspn
  7052.  
  7053.     FUNCTION
  7054.     scan a string until a character is found that matches any character
  7055.     in a second string (ANSI)
  7056.  
  7057.     SYNTAX
  7058.     #include <string.h>
  7059.     int len = strcspn(s, toks)
  7060.     const char *s;
  7061.     const char *toks;
  7062.  
  7063.     DESCRIPTION
  7064.     With strcspn, the string s is scanned until a character is found that
  7065.     matches any character in the string toks.  The number of characters
  7066.     skipped is returned.  If no character in s matches any character in
  7067.      toks then the length of the string s is returned.
  7068.     strcspn is normally used to search for whitespace within a string.
  7069.     Note that in many cases strpbrk is more useful than strcspn.
  7070.  
  7071.     INPUTS
  7072.     char *s;        pointer to string to scan
  7073.  
  7074.     char *toks;        pointer to string containing characters to
  7075.                 compare against
  7076.  
  7077.     RESULTS
  7078.     int len;        # of characters skipped in s before a match was
  7079.                 found.
  7080.  
  7081.     SEE ALSO
  7082.     strpbrk, strspn
  7083.  
  7084.     EXAMPLE
  7085.     #include <stdio.h>
  7086.     #include <string.h>
  7087.     #include <assert.h>
  7088.     main()
  7089.     {
  7090.        int len;
  7091.        len = strcspn("hello this is a test", " \tabcd");
  7092.        assert(len == 5);  /*  stopped at the first space  */
  7093.        len = strcspn("hello this is a test", " abl");
  7094.        assert(len == 2);  /*  stopped at the first 'l'    */
  7095.        len = strcspn("hello", "abcd");
  7096.        assert(len == 5);  /*  stopped at end of string 1  */
  7097.        return(0);
  7098.     }
  7099.  
  7100. dice/strdup                                                      dice/strdup
  7101.  
  7102.     FUNCTION
  7103.     duplicate a string using malloc (DICE)
  7104.  
  7105.     SYNTAX
  7106.     #include <string.h>
  7107.     char *s2 = strdup(s1);
  7108.     const char *s1;
  7109.  
  7110.     DESCRIPTION
  7111.     strdup allocates enough space to hold s1 including the terminating
  7112.     NULL and then copies s1 into this space, returning a pointer to the
  7113.     new string.  NULL is returned if space could not be allocated due to
  7114.     low memory conditions.    Note free may be used to free the returned
  7115.     string.  The amount allocated is (strlen(s1) + 1).
  7116.  
  7117.     || NOTE: This is a non-standard function and may not exist in other C
  7118.     || environments.
  7119.  
  7120.     INPUTS
  7121.     char *s1;        pointer to the string to duplicate
  7122.  
  7123.     RESULTS
  7124.     char *s2;        pointer to malloc'd space containing a duplicate
  7125.                 of the string s1 or NULL if space could not be
  7126.                 malloc'd.
  7127.  
  7128.     SEE ALSO
  7129.     malloc, free, strcpy, strlen
  7130.  
  7131.     EXAMPLE
  7132.     #include <stdio.h>
  7133.     #include <string.h>
  7134.     #include <assert.h>
  7135.     /*
  7136.      *  Modifying string constants (quoted strings) may
  7137.      *  not be entirely portable.  Normally one does not
  7138.      *  use strdup() to accomplish the following function
  7139.      *  but instead declares a char array statically
  7140.      *  initialized with the string, such as:
  7141.      *  char FuBar[] = { "This is a test" };
  7142.      *  Which can be modified in a portable fashion without
  7143.      *  having to duplicate the string.
  7144.      */
  7145.     main()
  7146.     {
  7147.        char *s1 = "this is a test";
  7148.        char *s2;
  7149.        s2 = strdup(s1);
  7150.        s2[0] = 'x';
  7151.        puts(s2);   /*  this is a test  */
  7152.        free(s2);
  7153.        s2 = strdup(s1);
  7154.        s2[1] = '0';
  7155.        puts(s2);   /*  this is a test  */
  7156.        free(s2);
  7157.        return(0);
  7158.     }
  7159.  
  7160. dice/strerror                                                  dice/strerror
  7161.  
  7162.     FUNCTION
  7163.     return error string associated with error code (ANSI)
  7164.  
  7165.     SYNTAX
  7166.     #include <string.h>
  7167.     const char *str = strerror(error); int error;
  7168.  
  7169.     DESCRIPTION
  7170.     strerror returns a read-only string associated with the specified
  7171.     error, usually taken from errno after some c.lib call fails.  An
  7172.     unknown error will result in the string "unknown error."
  7173.  
  7174.     INPUTS
  7175.     int error;        error code
  7176.  
  7177.     RESULTS
  7178.     char *str;        error string
  7179.  
  7180.     SEE ALSO
  7181.     perror
  7182.  
  7183.     EXAMPLE
  7184.     #include <stdio.h>
  7185.     #include <string.h>
  7186.     #include <errno.h>
  7187.     #include <assert.h>
  7188.     main()
  7189.     {
  7190.        FILE *fi;
  7191.        fi = fopen("ThisFileDoesNotExist", "r");
  7192.        assert(fi == NULL);
  7193.        puts(strerror(errno));
  7194.        return(0);
  7195.     }
  7196.  
  7197. dice/strftime                                                  dice/strftime
  7198.  
  7199.     FUNCTION
  7200.     convert broken down time into a string according to a format (ANSI)
  7201.  
  7202.     SYNTAX
  7203.     #include <time.h>
  7204.     size_t len = strftime(buf, max, fmt, tm)
  7205.     char *buf; size_t max;
  7206.     const char *fmt;
  7207.     const struct tm *tm;
  7208.  
  7209.     DESCRIPTION
  7210.     strftime formats a broken down time into a buffer according to a
  7211.     format string fmt.  The fmt string looks like a the format for a
  7212.     printf except with different control definitions:
  7213.  
  7214.     %%  A literal '%' character.
  7215.  
  7216.     %a  The locale's abbreviated name for the day of week.
  7217.  
  7218.     %A  The locale's full name for the  day of week.
  7219.  
  7220.     %b  The locale's abbr. name for the month.
  7221.  
  7222.     %B  The locale's full name for the month.
  7223.  
  7224.     %c  The locale's default representation for the date & time (ctime).
  7225.  
  7226.     %d  The day of the month 01-31.
  7227.  
  7228.     %H  The hour 00-23 (24 hour time).
  7229.  
  7230.     %I  The hour 01-12 (12 hour time).
  7231.  
  7232.     %j  The day in the year 001-366.
  7233.  
  7234.     %m  The month 01-12.
  7235.  
  7236.     %M  The minute 00-59.
  7237.  
  7238.     %p  Indication of morning or afternoon.  In the US: "AM" or "PM".
  7239.  
  7240.     %S  The second 00-59.
  7241.  
  7242.     %U  The week of the year 00-53, Sunday is the first day in a week.
  7243.  
  7244.     %w  The day of the week 0-6, Sunday=0 (standard).
  7245.  
  7246.     %W  The day of the week 0-6, monday=0.
  7247.  
  7248.     %x  The locale's default representation for the date only.
  7249.  
  7250.     %X  The locale's default representation for the time only.
  7251.  
  7252.     %y  The year mod 100 (00-99).
  7253.  
  7254.     %Y  The full year (e.g. 1990).
  7255.  
  7256.     %Z  The name of the locale's time zone, nothing if unknown.
  7257.  
  7258.         ## WARNING: There must be at least max + 1 bytes in buf or you
  7259.         ## might unexpectedly overwrite memory.
  7260.  
  7261.     INPUTS
  7262.     char *buf;        buffer to write formatted string into
  7263.  
  7264.     size_t max;        maximum size of buffer - 1
  7265.  
  7266.     char *fmt;        format string
  7267.  
  7268.     struct tm *tm;        broken down time
  7269.  
  7270.     RESULTS
  7271.     size_t len;        length of formatted string in buffer or 0 if the
  7272.                 maximum was exceeded.
  7273.  
  7274.     SEE ALSO
  7275.     time, localtime, asctime, ctime, clock
  7276.  
  7277.     EXAMPLE
  7278.     #include <stdio.h>
  7279.     #include <time.h>
  7280.  
  7281.     main()
  7282.     {
  7283.        time_t t = time(NULL);
  7284.        struct tm *tp = localtime(&t);
  7285.        char buf[256];
  7286.        strftime(buf, sizeof(buf) - 1,
  7287.             "Now is %A %d %B %Y %X",  tp);
  7288.        puts(buf);
  7289.        return(0);
  7290.     }
  7291.  
  7292. dice/stricmp                                                    dice/stricmp
  7293.  
  7294.     FUNCTION
  7295.     compare two strings, case insensitive (UNIX)
  7296.  
  7297.     SYNTAX
  7298.     #include <string.h>
  7299.     int r = stricmp(s1, s2);
  7300.     const char *s1;
  7301.     const char *s2;
  7302.  
  7303.     DESCRIPTION
  7304.     stricmp compares two strings, returning: -1 if    s1 < s2, 0 if  s1 ==
  7305.     s2, or 1 if  s1 > s2. differs from strcmp in that case is ignored for
  7306.     alphabetic characters, i.e. a == A.
  7307.  
  7308.     || NOTE: NOTE= stricmp converts the chars in the string to unsigned
  7309.     || quantities when comparing them.  However, for portability you
  7310.     || should not stricmp strings containing negative characters (bit 7
  7311.     || set) for anything other than checking the result against 0.    Use
  7312.     || the memcmp routine instead.
  7313.  
  7314.     INPUTS
  7315.     char *s1;        pointer to first string
  7316.  
  7317.     char *s2;        pointer to second string
  7318.  
  7319.     RESULTS
  7320.     int r;            -1, 0, or 1.
  7321.  
  7322.     SEE ALSO
  7323.     strcmp, strncmp
  7324.  
  7325.     EXAMPLE
  7326.     #include <stdio.h>
  7327.     #include <string.h>
  7328.     #include <assert.h>
  7329.     main()
  7330.     {
  7331.        char *s1 = "abCa";
  7332.        char *s2 = "aBcD";
  7333.        char *s3 = "aBCX";
  7334.        char *s4 = "ABCdx";
  7335.        char *s5 = "Abc";
  7336.        char *x2 = "ABCD";
  7337.        int r;
  7338.        r = stricmp(s2, x2); /* string s2 same as x2 */
  7339.        assert(r == 0);
  7340.        r = stricmp(s2, s1); /* string s2 larger than s1 */
  7341.        assert(r > 0);
  7342.        r = stricmp(s2, s3);
  7343.        assert(r < 0);
  7344.        r = stricmp(s2, s4);
  7345.        assert(r < 0);
  7346.        r = stricmp(s2, s5);
  7347.        assert(r > 0);
  7348.        return(0);
  7349.     }
  7350.  
  7351. dice/strins                                                      dice/strins
  7352.  
  7353.     FUNCTION
  7354.     insert one string within another (DICE)
  7355.  
  7356.     SYNTAX
  7357.     #include <string.h>
  7358.     void strins(d, s);
  7359.     char *d;
  7360.     const char *s;
  7361.  
  7362.     DESCRIPTION
  7363.     strins inserts string s into d by shifting the string in d over
  7364.     strlen(s) spaces and then copying s into the newly made hold (except
  7365.     for the NULL, of course).  This result is s inserted into d.
  7366.  
  7367.     || NOTE: There must be enough room in d to insert s; if d is an array
  7368.     || of 32 chars and contains a string of 8 chars you can insert
  7369.     || another string of, say, 10 chars, but not of 30 chars.  strins is
  7370.     || not an ANSI standard function.
  7371.  
  7372.     INPUTS
  7373.     char *d;        destination to insert in front of
  7374.  
  7375.     char *s;        source string to insert
  7376.  
  7377.     SEE ALSO
  7378.     strcpy, strcat, strlen
  7379.  
  7380.     EXAMPLE
  7381.     #include <stdio.h>
  7382.     #include <string.h>
  7383.     main()
  7384.     {
  7385.        char buf[32];
  7386.        strcpy(buf, "This is a test");
  7387.        strins(buf + 5, "<gak!> ");
  7388.        puts(buf);
  7389.        /*  This <gak!> is a test  */
  7390.        return(0);
  7391.     }
  7392.  
  7393. dice/strlen                                                      dice/strlen
  7394.  
  7395.     FUNCTION
  7396.     returns length of a string (ANSI)
  7397.  
  7398.     SYNTAX
  7399.     #include <string.h>
  7400.     int len = strlen(s);
  7401.     const char *s;
  7402.  
  7403.     DESCRIPTION
  7404.     When this function is used, the length of the requested string is
  7405.     returned. The string is scanned until a NULL terminator is found and
  7406.     the number of characters (not including the NULL) is returned.
  7407.  
  7408.     :: Beginner's Note: The length returned by strlen does not include
  7409.     :: the NULL.  It is common error to forget this fact and reserve one
  7410.     :: too few bytes of storage!
  7411.  
  7412.     INPUTS
  7413.     char *s;        string to obtain length of
  7414.  
  7415.     RESULTS
  7416.     int len;        length of string
  7417.  
  7418.     SEE ALSO
  7419.     strcpy, strcat
  7420.  
  7421.     EXAMPLE
  7422.     #include <stdio.h>
  7423.     #include <string.h>
  7424.     main(int ac, char **av)
  7425.     {
  7426.         if( ac  1 )
  7427.         {
  7428.         printf("%s is %d byte(s) long\n",
  7429.                av[1], strlen( av[1] ) );
  7430.         } else
  7431.         printf("Gimme, gimme, gimme!!\n");
  7432.     }
  7433.  
  7434. dice/strncat                                                    dice/strncat
  7435.  
  7436.     FUNCTION
  7437.     concatenate a string to an existing string up to a maximum number of
  7438.     characters (ANSI)
  7439.  
  7440.     SYNTAX
  7441.     #include <string.h>
  7442.     char *d = strncat(d, s, n);
  7443.     char *d;
  7444.     const char *s;
  7445.     int n;
  7446.  
  7447.     DESCRIPTION
  7448.     strncat scans the destination buffer for the NULL terminator and then
  7449.     appends the source string to the destination buffer (removing the
  7450.     NULL terminator and placing one at the end after the concatenation).
  7451.     However, only up to n characters is concatenated including the NULL.
  7452.     If the source string is exactly n characters long no NULL will be
  7453.     appended.  If the source string is longer than n characters then only
  7454.     the first n characters of the source string will be appended (and no
  7455.     NULL will be).    A pointer to the beginning of the destination buffer
  7456.     is returned.
  7457.  
  7458.     INPUTS
  7459.     char *d;        pointer to destination buffer which already
  7460.                 contains a string (which could be just a \0).
  7461.  
  7462.     char *s;        pointer to the NULL terminated source string
  7463.  
  7464.     int n;            maximum number of characters to concatenate
  7465.  
  7466.     RESULTS
  7467.     char *d;        same as the first argument, a pointer to the
  7468.                 destination buffer.
  7469.  
  7470.     SEE ALSO
  7471.     strncpy, strcpy, strcat
  7472.  
  7473.     EXAMPLE
  7474.     #include <stdio.h>
  7475.     #include <string.h>
  7476.     main()
  7477.     {
  7478.        char d[32];           char *p;
  7479.        char *s1 = "grid";  char *s2 = "lock";
  7480.  
  7481.        strcpy( d, s1 );
  7482.        p = strncat( d, s2, 10 );
  7483.        puts( d );  /* gridlock */
  7484.  
  7485.        strcpy( d,I s1 );
  7486.        p = strncat( d, s2, 3 );
  7487.        puts( d );  /* gridloc  */
  7488.  
  7489.        return(0);
  7490.     }
  7491.  
  7492. dice/strncmp                                                    dice/strncmp
  7493.  
  7494.     FUNCTION
  7495.     compare two strings up to a maximum number of characters (ANSI)
  7496.  
  7497.     SYNTAX
  7498.     #include <string.h>
  7499.     int r = strncmp(s1, s2, n);
  7500.     const char *s1;
  7501.     const char *s2;
  7502.     int n;
  7503.  
  7504.     DESCRIPTION
  7505.     strncmp compares two strings, returning:  -1 if s1 < s2,  0 if s1 ==
  7506.     s2, or 1 if  s1 > s2.    strncmp works like strcmp but only up to n
  7507.     characters will be compared.  If all characters compare when n is
  7508.     reached 0 is returned indicating that the strings matched. Fewer
  7509.     characters might be compared if either string terminates (w/ a NULL)
  7510.     before the maximum is reached or a compare fails (scan is stopped and
  7511.     -1 or 1 is returned immediately).
  7512.  
  7513.     || NOTE: strncmp converts the chars in the string to unsigned
  7514.     || quantities when comparing them.  However, for portability you
  7515.     || should not strncmp strings containing negative characters (bit 7
  7516.     || set) for anything other than checking the result against 0.    Use
  7517.     || the memcmp routine instead.
  7518.  
  7519.     INPUTS
  7520.     char *s1;        pointer to first string
  7521.  
  7522.     char * s2;        pointer to second string
  7523.  
  7524.     int n;            maximum number of characters to compare
  7525.  
  7526.     RESULTS
  7527.     int r;            -1, 0, or 1.
  7528.  
  7529.     SEE ALSO
  7530.     stricmp
  7531.  
  7532.     EXAMPLE
  7533.     #include <stdio.h>
  7534.     #include <string.h>
  7535.     #include <assert.h>
  7536.     main()
  7537.     {
  7538.        char *s1 = "abcaq";
  7539.        char *s2 = "abcdr";
  7540.        char  *s3 = "abcxs";
  7541.        char *s4 = "abcdxx";
  7542.        char *s5 = "abc";
  7543.        char *x2 = "abcdt";
  7544.        int r;   r = strncmp(s2, x2, 4);
  7545.        assert(r == 0);
  7546.        r = strncmp(s2, s1, 4);
  7547.        assert(r > 0);
  7548.        r = strncmp(s2, s3, 4);
  7549.        assert(r < 0);
  7550.        r = strncmp(s2, s4, 8);
  7551.        assert(r < 0);
  7552.        r = strncmp(s2, s5, 4);
  7553.        assert(r > 0);
  7554.        return(0);
  7555.     }
  7556.  
  7557. dice/strncpy                                                    dice/strncpy
  7558.  
  7559.     FUNCTION
  7560.     copy a string returning a pointer to the beginning of the destination
  7561.     until NULL or the specified number of characters is reached (ANSI)
  7562.  
  7563.     SYNTAX
  7564.     #include <string.h>
  7565.     char *ptr = strncpy(d, s, n);
  7566.     char *d;
  7567.     const char *s;
  7568.     int n;
  7569.  
  7570.     DESCRIPTION
  7571.     strncpy copies the NULL terminated string pointed to by s to the
  7572.     buffer d. The NULL is normally copied.    The first argument is
  7573.     returned (a pointer to the buffer d). The copy will also be
  7574.     terminated if the specified maximum is reached, in which case the
  7575.     NULL is NOT copied (which makes the function useless - but hey, it
  7576.     does make it standard).
  7577.  
  7578.     INPUTS
  7579.     char *d;        pointer to beginning of destination buffer
  7580.  
  7581.     char *s;        pointer to beginning of source string
  7582.  
  7583.     int len;        maximum number of characters to copy
  7584.  
  7585.     RESULTS
  7586.     char *ptr;        same as the destination buffer pointer (d).
  7587.  
  7588.     SEE ALSO
  7589.     stpcpy, strcpy
  7590.  
  7591.     EXAMPLE
  7592.     #include <stdio.h>
  7593.     #include <string.h>
  7594.     #include <assert.h>
  7595.     main()
  7596.     {
  7597.        char *buf1 = "hello";
  7598.        char *buf2 = "123";
  7599.        char dest[32];
  7600.  
  7601.        strncpy(dest, buf1, 8);
  7602.        strcat(dest, buf2);
  7603.        puts(dest);           /* hello123 */
  7604.  
  7605.        dest[2] = 23;
  7606.        strncpy(dest, buf1, 2);
  7607.        assert(dest[2] == 23);  /* copy just two */
  7608.        dest[2] = 0;  /* we have to add the NULL */
  7609.        puts(dest);           /* he */
  7610.  
  7611.        strcat(dest, buf2);       /* he123   */
  7612.        puts(dest);
  7613.        return(0);
  7614.     }
  7615.  
  7616. dice/strnicmp                                                  dice/strnicmp
  7617.  
  7618.     FUNCTION
  7619.     compare two strings up to a maximum number of characters, case
  7620.     insensitive (UNIX)
  7621.  
  7622.     SYNTAX
  7623.     #include <string.h>
  7624.     int r = strnicmp(s1, s2, n);
  7625.     const char *s1;
  7626.     const char *s2;
  7627.     int n;
  7628.  
  7629.     DESCRIPTION
  7630.     strnicmp compares two strings, returning:  -1,    s1 < s2;  0, s1 ==
  7631.     s2;   1,  s1 > s2.  strnicmp differs from strcmp in that case is
  7632.     ignored for alphabetic characters (i.e., a == A) and only up to n
  7633.     characters are compared. Refer to stricmp and strncmp for other
  7634.     examples.
  7635.  
  7636.     || NOTE: strnicmp converts the chars in the string to unsigned
  7637.     || quantities when comparing them.  However, for portability you
  7638.     || should not strnicmp strings containing negative characters (bit 7
  7639.     || set) for anything other than checking the result against 0.    Use
  7640.     || the memcmp routine instead.
  7641.  
  7642.     INPUTS
  7643.     char *s1;        pointer to first string
  7644.  
  7645.     char *s2;        pointer to second string
  7646.  
  7647.     int n;            maximum # of characters to compare
  7648.  
  7649.     RESULTS
  7650.     int r;            -1, 0, or 1.
  7651.  
  7652.     SEE ALSO
  7653.     strcmp, strncmp, stricmp
  7654.  
  7655.     EXAMPLE
  7656.     #include <stdio.h>
  7657.     #include <string.h>
  7658.     #include <assert.h>
  7659.     main()
  7660.     {
  7661.        char *s1 = "aBcAQ";
  7662.        char *s2 = "abCDR";
  7663.        char *s3 = "ABcXs";
  7664.        char *s4 = "aBCDxX";
  7665.        char *s5 = "aBC";
  7666.        char *x2 = "AbCDt";
  7667.        int r;
  7668.        r = strnicmp(s2, x2, 4);
  7669.        assert(r == 0);
  7670.        r = strnicmp(s2, s1, 4);
  7671.        assert(r > 0);
  7672.        r = strnicmp(s2, s3, 4);
  7673.        assert(r < 0);
  7674.        r = strnicmp(s2, s4, 8);
  7675.        assert(r < 0);
  7676.        r = strnicmp(s2, s5, 4);
  7677.        assert(r > 0);
  7678.        return(0);
  7679.     }
  7680.  
  7681. dice/strpbrk                                                    dice/strpbrk
  7682.  
  7683.     FUNCTION
  7684.     search for specific characters in a string (ANSI)
  7685.  
  7686.     SYNTAX
  7687.     #include <string.h>
  7688.     char *ptr = strpbrk(s, toks)
  7689.     const char *s;
  7690.     char *toks;
  7691.  
  7692.     DESCRIPTION
  7693.     strpbrk searches the string s for any character in the string toks.
  7694.     For example, when searching for whitespace in s, toks would contain
  7695.     the space and tab character.  If no character in s matches any
  7696.     character in toks then NULL is returned.
  7697.  
  7698.     INPUTS
  7699.     char *s;        pointer to string to scan
  7700.  
  7701.     char *toks;        pointer to string containing tokens to scan for
  7702.  
  7703.     RESULTS
  7704.     char *ptr;        pointer to point in s where the character matches
  7705.                 any character in toks, or NULL if s was
  7706.                 exhausted.
  7707.  
  7708.     SEE ALSO
  7709.     strtok
  7710.  
  7711.     EXAMPLE
  7712.     #include <stdio.h>
  7713.     #include <string.h>
  7714.     #include <assert.h>
  7715.     main()
  7716.     {
  7717.        char *s = "This  \tis a test";
  7718.        char *ptr;
  7719.        ptr = strpbrk(s, " \t");
  7720.        assert(ptr == s + 4);
  7721.        ptr = strpbrk(ptr + 1, " \t");
  7722.        assert(ptr == s + 5);
  7723.        ptr = strpbrk(ptr + 1, " \t");
  7724.        assert(ptr == s + 6);
  7725.        ptr = strpbrk(ptr + 1, " \t");
  7726.        assert(ptr == s + 9);
  7727.        ptr = strpbrk(ptr + 1, "xyz"); /* doesn't find 'm */
  7728.        assert(ptr == NULL);
  7729.        return(0);
  7730.     }
  7731.  
  7732. dice/strrchr                                                    dice/strrchr
  7733.  
  7734.     FUNCTION
  7735.     search for a character in a string, scan backwards (ANSI)
  7736.  
  7737.     SYNTAX
  7738.     #include <string.h>
  7739.     char *ptr = strrchr(s, c)
  7740.     const char *s;
  7741.     int c;
  7742.  
  7743.     DESCRIPTION
  7744.     strrchr searches for the character c within the string pointed to by
  7745.     s. The terminating NULL at the end of s is included in the search.
  7746.     The string is searched backwards. A pointer to the last occurrence of
  7747.     c in s is returned or NULL if c could not be found.  C is converted
  7748.     to an 8 bit quantity by strrchr.
  7749.  
  7750.     || NOTE: The ANSI spec does not say anything about including the NULL
  7751.     || character in the search for strrchr and some implementation may
  7752.     || thus not implement this properly.
  7753.  
  7754.     INPUTS
  7755.     char *s;        pointer to the string to search
  7756.  
  7757.     int c;            character to search for
  7758.  
  7759.     RESULTS
  7760.     char *ptr;        pointer to the last occurrence of character c in
  7761.                 s or NULL if c could not be found in s.
  7762.  
  7763.     SEE ALSO
  7764.     strchr
  7765.  
  7766.     EXAMPLE
  7767.     #include <stdio.h>
  7768.     #include <string.h>
  7769.     #include <assert.h>
  7770.     main()
  7771.     {
  7772.        char *s = "this is a test";
  7773.        char *ptr;
  7774.        ptr = strrchr(s, 'i');
  7775.        assert(ptr == s + 5);
  7776.        puts(ptr);       /*  "is a test"  */
  7777.        ptr = strrchr(s, 'x');
  7778.        assert(ptr == NULL);
  7779.        return(0);
  7780.     }
  7781.  
  7782. dice/strspn                                                      dice/strspn
  7783.  
  7784.     FUNCTION
  7785.     scan a string until a character is found that does not match some
  7786.     character in a second string (ANSI)
  7787.  
  7788.     SYNTAX
  7789.     #include <string.h>
  7790.     int len = strspn(s, toks)
  7791.     const char *s;
  7792.     const char *toks;
  7793.  
  7794.     DESCRIPTION
  7795.     The string s is scanned until a character is found that does not
  7796.     match any character in the string toks.  The number of characters
  7797.     skipped is returned.  If every character in s matches some character
  7798.     in toks then the length of the string s is returned.
  7799.  
  7800.     strspn is normally used to skip whitespace within a string.
  7801.  
  7802.     INPUTS
  7803.     char *s;        pointer to string to scan
  7804.  
  7805.     char *toks;        pointer to string containing characters to
  7806.                 compare against
  7807.  
  7808.     RESULTS
  7809.     int len;        # of characters skipped in s before a match could
  7810.                 not be found
  7811.  
  7812.     SEE ALSO
  7813.     strpbrk, strcspn
  7814.  
  7815.     EXAMPLE
  7816.     #include <stdio.h>
  7817.     #include <string.h>
  7818.     #include <assert.h>
  7819.  
  7820.     main()
  7821.     {
  7822.        int len;
  7823.        len = strspn("  \t \t\t abcde test", " \t ");
  7824.        assert(len == 7);  /*  stopped at the 'a'  */
  7825.        len = strspn("abcd efg", " ");
  7826.        assert(len == 0);  /*  stopped at the 'a'  */
  7827.        len = strspn("   \t\t ", " \t");
  7828.        assert(len == 6);  /*  all match, len=strlen(str); */
  7829.        return(0);
  7830.     }
  7831.  
  7832. dice/strstr                                                      dice/strstr
  7833.  
  7834.     FUNCTION
  7835.     find sub-string within another string (ANSI)
  7836.  
  7837.     SYNTAX
  7838.     #include <string.h>
  7839.     char *ptr = strstr(s, sub);
  7840.     const char *s;
  7841.     const char *sub;
  7842.  
  7843.     DESCRIPTION
  7844.     The string s is scanned until the sub-string sub matches the string
  7845.     beginning at the current scan point, and a pointer to the sub-string
  7846.     within s is returned.  If the sub-string could not be found NULL is
  7847.     returned.
  7848.  
  7849.     INPUTS
  7850.     char *s;        pointer to string to scan
  7851.  
  7852.     char *toks;        pointer to string containing characters to
  7853.                 compare against
  7854.  
  7855.     RESULTS
  7856.     char *ptr;        point in s where sub string was found or NULL if
  7857.                 sub string could not be found.
  7858.  
  7859.     SEE ALSO
  7860.     strpbrk, strcspn
  7861.  
  7862.     EXAMPLE
  7863.     #include <stdio.h>
  7864.     #include <string.h>
  7865.     #include <assert.h>
  7866.  
  7867.     main()
  7868.     {
  7869.        char *s = "abcdefghijklmnopqrstuvwxyz";
  7870.        char *ptr;
  7871.        ptr = strstr(s, "klm");
  7872.        assert(ptr == s + 10);
  7873.        puts(ptr);  /*  klmnopqrstuvwxyz    */
  7874.        return(0);
  7875.     }
  7876.  
  7877. dice/strtod                                                      dice/strtod
  7878.  
  7879.     FUNCTION
  7880.     convert string to fp double (ANSI)
  7881.  
  7882.     LIBRARY
  7883.     m.lib
  7884.  
  7885.     SYNTAX
  7886.     #include <string.h>
  7887.     double d = strtod(s, &tp);
  7888.     const char *s;
  7889.     char *tp;
  7890.  
  7891.     DESCRIPTION
  7892.     strtod converts a string to a floating point double.  Initial
  7893.     whitespace is skipped.    The format of the fp number in the string is
  7894.     then:
  7895.  
  7896.     {+/-/<nothing>}ddddd[.ddddd][E{+/-/<nothing>}dddd]
  7897.  
  7898.     Example fp strings: " +1.234E-3", "-1234", "6.5676E4", "214.2345"
  7899.  
  7900.     INPUTS
  7901.     char *s;        pointer to string containing fp number
  7902.  
  7903.     char **tp;        pointer to pointer, the pointer is modified to
  7904.                 point to the end of the scanned fp number.
  7905.  
  7906.     RESULTS
  7907.     double d;        resulting double
  7908.  
  7909.     EXAMPLE
  7910.     /*
  7911.      *  compile -lm to include math library
  7912.      */
  7913.     #include <stdio.h>
  7914.     #include <string.h>
  7915.  
  7916.     main()
  7917.     {
  7918.        double d;
  7919.        char *tp;
  7920.        d = strtod("1.2134 3.45E2", &tp);
  7921.        printf("1.2134 = %lf\n", d);    /*  1.213400    */
  7922.        d = strtod(tp, &tp);
  7923.        printf("3.45E2 = %lf\n", d);    /*  345.000000  */
  7924.        return(0);
  7925.     }
  7926.  
  7927. dice/strtok                                                      dice/strtok
  7928.  
  7929.     FUNCTION
  7930.     break up a string into arguments (ANSI)
  7931.  
  7932.     SYNTAX
  7933.     #include <string.h>
  7934.     char *arg = strtok(s, toks)
  7935.     char *s;
  7936.     const char *toks;
  7937.  
  7938.     DESCRIPTION
  7939.     strtok breaks up a string into arguments.  It determines the break
  7940.     point from the toks string which contains a set of whitespace
  7941.     characters (usually \t to mean space and tab).    The first call to
  7942.     strtok should specify the string s and toks. Initial whitespace is
  7943.     skipped and the string is then scanned until the end of the first
  7944.     argument is found.  The string is then modified: a NULL is placed at
  7945.     the end of the first argument and a pointer to the beginning of the
  7946.     first argument is returned.
  7947.  
  7948.     Further calls to strtok should pass a NULL for the string s, which
  7949.     tells strtok to continue scanning the original string (whose pointer
  7950.     was stored in a static char * within strtok). strtok returns
  7951.     arguments until the string is exhausted, in which case it returns
  7952.     NULL.  The initial call to strtok can return NULL if the passed
  7953.     string s contains nothing but whitespace (as specified by toks).  You
  7954.     can change the toks string at any time (i.e. pass a different toks
  7955.     string to strtok).
  7956.  
  7957.     ## WARNING: strtok modifies the source string and returns pointers
  7958.     ## into it.
  7959.  
  7960.     INPUTS
  7961.     char *s;        pointer to string to parse
  7962.  
  7963.     char *toks;        pointer to string containing whitespace
  7964.                 characters (argument delimiters)
  7965.  
  7966.     RESULTS
  7967.     char *arg;        pointer into s to next argument that is NULL
  7968.                 terminated (s is modified).
  7969.  
  7970.     SEE ALSO
  7971.     strspn, strcspn
  7972.  
  7973.     EXAMPLE
  7974.     #include <stdio.h>
  7975.     #include <string.h>
  7976.  
  7977.     main()
  7978.     {
  7979.        char buf[32];
  7980.        char *arg;
  7981.        const char *ws = " \t";
  7982.        /*
  7983.         *  'This' 'is' 'a' 'test!'
  7984.         */
  7985.        strcpy(buf, "  This  is \t \t a test!");
  7986.        for (arg = strtok(buf, ws);
  7987.         arg; arg = strtok(NULL, ws))
  7988.        {
  7989.           printf("arg = '%s'\n", arg);
  7990.        }
  7991.        return(0);
  7992.     }
  7993.  
  7994. dice/strtol,strtoul                                      dice/strtol,strtoul
  7995.  
  7996.     FUNCTION
  7997.     convert string to integer (ANSI)
  7998.  
  7999.     SYNTAX
  8000.     #include <string.h>
  8001.     long v = strtol(str, &tail, base);
  8002.     unsigned long v = strtoul(str, &tail, base);
  8003.     const char *str;
  8004.     char *tail;
  8005.     int base;
  8006.  
  8007.     DESCRIPTION
  8008.     strtol converts a string into an integer using the specified base
  8009.     0-36.  If a non-zero base is specified conversion is done using that
  8010.     base (hex numbers may still be preceded by '0x' or '0X').  If 0 is
  8011.     specified for the base then the base is determined from the first one
  8012.     or two characters of the number portion of the string:
  8013.  
  8014.         0     octal
  8015.         1-9     decimal
  8016.         0x     hex (0x or 0X)
  8017.  
  8018.     For bases larger than 10, alphabetic characters are used to represent
  8019.     digits. Either lower case or upper case letters may be used.  strtol
  8020.     stores a pointer to the remainder of the string after the conversion.
  8021.     strtol ignores any whitespace at the beginning of the string and also
  8022.     handles an optional negative sign (which may precede the numerical
  8023.      portion of the string).
  8024.     If successful strtol returns the converted value as a long, 0 if it
  8025.     was unable to convert anything, and an undefined result if the
  8026.     converted value was out of range.
  8027.  
  8028.     || NOTE: strtol supersedes atoi and atol.
  8029.  
  8030.     INPUTS
  8031.     char *str;        pointer to string to convert
  8032.  
  8033.     char **tail;        *tail modified to point to just after last
  8034.                 character converted
  8035.  
  8036.     int base;        base of conversion or 0 for autoselect
  8037.  
  8038.     RESULTS
  8039.     long v;         converted result, an integer, or 0 if no
  8040.                 conversion could be done.
  8041.  
  8042.     SEE ALSO
  8043.     atoi, atol, strtod
  8044.  
  8045.     EXAMPLE
  8046.     #include <stdio.h>
  8047.     #include <string.h>
  8048.  
  8049.     main(int ac, char**av)
  8050.     {
  8051.        long v;
  8052.        char *tail;
  8053.        if (ac != 3)
  8054.        {
  8055.           puts("testprg <string> <base>");
  8056.           puts("testprg 0123abc 0");
  8057.           puts("testprg 0x1000 0");
  8058.           puts("testprg 0123abc 16");
  8059.           exit(1);
  8060.        }
  8061.        v = strtol(av[1], &tail, atoi(av[2]));
  8062.        printf("v = %d, tail = %s\n", v, tail);
  8063.        return(0);
  8064.     }
  8065.  
  8066. dice/system                                                      dice/system
  8067.  
  8068.     FUNCTION
  8069.     call system shell with a command line (ANSI)
  8070.  
  8071.     SYNTAX
  8072.     #include <stdio.h>
  8073.     #include <stdlib.h>
  8074.     int r = system(buf);
  8075.     const char *buf;
  8076.  
  8077.     DESCRIPTION
  8078.     system calls the system shell with the specified command line,
  8079.     returning the exit code of the command or -1 if it was unable to run
  8080.     the command.
  8081.  
  8082.     || NOTE: FOR PROGRAMS COMPILED UNDER 1.3, even if run in 2.0
  8083.     || environment, the system call will not return the exit code from
  8084.     || the command, but return -1 if could not be run, 0 if it could.
  8085.  
  8086.     || NOTE: FOR PROGRAMS COMPILED UNDER 2.0, system will use the 2.0
  8087.     || calls and return a proper exit code when running under 2.0, and
  8088.     || will use execute if running under 1.3.
  8089.  
  8090.     INPUTS
  8091.     char *buf;        command line to run, like a normal AmigaDOS CLI
  8092.                 command line.
  8093.  
  8094.     RESULTS
  8095.     int r;            return code
  8096.  
  8097.     EXAMPLE
  8098.     main()
  8099.     {
  8100.     int r;
  8101.         r = system("c:type s:startup-sequence");
  8102.         printf("System returns %d\n", r);
  8103.     }
  8104.  
  8105. dice/tan,ftan                                                  dice/tan,ftan
  8106.  
  8107.     FUNCTION
  8108.     tan: return tan of a double quantity (ANSI)
  8109.     ftan: return tan of a float quantity (ANSI)
  8110.  
  8111.     LIBRARY
  8112.     m.lib
  8113.  
  8114.     SYNTAX
  8115.     #include <math.h>
  8116.     double a = tan(b); double b;
  8117.     float  c = ftan(d); float  d;
  8118.  
  8119.     DESCRIPTION
  8120.     tan returns the tangent of a double quantity; ftan returns the
  8121.     tangent of a floating point quantity.
  8122.  
  8123.     INPUTS
  8124.     double b;        double floating point value
  8125.  
  8126.     float d;        float floating point value
  8127.  
  8128.     RESULTS
  8129.     double a;        double floating point value
  8130.  
  8131.     float c;        float floating point value
  8132.  
  8133.     SEE ALSO
  8134.     acos, asin, atan, cos, exp, fabs, log, log10, pow, sin, sqrt, tan,
  8135.     facos, fasin
  8136.  
  8137.     EXAMPLE
  8138.     /*
  8139.      *  compile with the math library -lm
  8140.      */
  8141.     #include <math.h>
  8142.     #include <stdio.h>
  8143.     main()
  8144.     {
  8145.        {
  8146.           double a = tan(0.25);
  8147.           printf("tan 0.25 = %lf\n", a); /* 0.2553 */
  8148.        }
  8149.        {  /*  less accuracy   */
  8150.           float a = ftan(0.25);
  8151.           printf("tan 0.25 = %lf\n", (double)a);
  8152.        }
  8153.        return(0);
  8154.     }
  8155.  
  8156. dice/time                                                          dice/time
  8157.  
  8158.     FUNCTION
  8159.     get current time (ANSI)
  8160.  
  8161.     SYNTAX
  8162.     #include <time.h>
  8163.     time_t t = time(NULL);
  8164.     or
  8165.     time(&t);
  8166.     time_t t;
  8167.  
  8168.     DESCRIPTION
  8169.     time returns the current time as a time_t and also copies it into a
  8170.     time_t if the address of said is passed as an argument. You may pass
  8171.     NULL as an argument in which case the time is only returned.
  8172.  
  8173.     The time is returned as seconds since some base date, time_t is
  8174.     normally an unsigned long.
  8175.  
  8176.     INPUTS
  8177.     time_t *t;        pointer to a time_t or NULL
  8178.  
  8179.     RESULTS
  8180.     time_t t;        a time_t
  8181.  
  8182.     SEE ALSO
  8183.     time, localtime, asctime, strftime, ctime, clock
  8184.  
  8185.     EXAMPLE
  8186.     #include <stdio.h>
  8187.     #include <time.h>
  8188.  
  8189.     main()
  8190.     {
  8191.        time_t t = time(NULL);
  8192.        printf("t = %u\n", t);
  8193.        return(0);
  8194.     }
  8195.  
  8196. dice/tmpfile                                                    dice/tmpfile
  8197.  
  8198.     FUNCTION
  8199.     create a temporary file (ANSI)
  8200.  
  8201.     SYNTAX
  8202.     #include <stdio.h>
  8203.     FILE *fp = tmpfile(void);
  8204.  
  8205.     DESCRIPTION
  8206.     tmpfile creates a temporary file and returns a file pointer.  The
  8207.     name of the file is not accessible. The file pointer is available or
  8208.     reading, writing, and seeking (as in rewind, fseek).  The file is
  8209.     initially empty.  This call may be used to create a temporary file
  8210.     that will automatically be removed when you fclose it.    tmpfile
  8211.     returns a FILE pointer or NULL if it was unable to create the file.
  8212.  
  8213.     INPUTS
  8214.     none
  8215.  
  8216.     RESULTS
  8217.     FILE *fp;        opened temporary file
  8218.  
  8219.     SEE ALSO
  8220.     tmpnam, fopen, fclose
  8221.  
  8222.     EXAMPLE
  8223.     #include <stdio.h>
  8224.     #include <assert.h>
  8225.     main()
  8226.     {
  8227.        FILE *fp = tmpfile();
  8228.        char buf[256];
  8229.        assert(fp);
  8230.        fputs("This is a test of\n"
  8231.             "a temporary file\n"
  8232.             "fubar bletch\n", fp);
  8233.        rewind(fp);
  8234.        while (fgets(buf, sizeof(buf), fp))
  8235.        {
  8236.           fputs(buf, stdout);
  8237.        }
  8238.        fclose(fp);      /* close and delete the file     */
  8239.        return(0);
  8240.     }
  8241.  
  8242. dice/tmpnam                                                      dice/tmpnam
  8243.  
  8244.     FUNCTION
  8245.     create a unique, temporary file name (ANSI)
  8246.  
  8247.     SYNTAX
  8248.     #include <stdio.h>
  8249.     char *filename = tmpnam(buf);
  8250.     char *buf;
  8251.  
  8252.     DESCRIPTION
  8253.     tmpnam creates a unique temporary file name meant never to be seen by
  8254.     the user.  The filename tmpnam creates will be no more than L_tmpnam
  8255.     bytes long (L_tmpnam is a macro in <stdio.h>), including the NULL so
  8256.      you can simply declare a buffer: char buf[L_tmpnam];.
  8257.     tmpnam returns the buffer into which it created the temporary file
  8258.     name.  If you specify a non-NULL buffer it returns its first
  8259.     argument.  If you pass NULL to tmpnam then tmpnam will use its down
  8260.     internal static buffer (overwriting any previous name that was stored
  8261.     in said buffer) and return a pointer to that.
  8262.  
  8263.     INPUTS
  8264.     char *buf;        optional buffer of at least L_tmpnam bytes to
  8265.                 hold the temporary file name or NULL to have
  8266.                 tmpnam() use its own internal buffer.
  8267.  
  8268.     RESULTS
  8269.     char *ptr;        pointer to buffer (buf if buf != NULL)
  8270.  
  8271.     SEE ALSO
  8272.     tmpfile
  8273.  
  8274.     EXAMPLE
  8275.     #include <stdio.h>
  8276.     #include <assert.h>
  8277.     main()
  8278.     {
  8279.        char buf[L_tmpnam];      char *ptr;
  8280.        ptr = tmpnam(NULL);      puts(ptr);
  8281.        assert(tmpnam(buf) == buf);
  8282.        /*  returns argument */
  8283.        puts(buf);      /*  haven't overwritten it yet */
  8284.        printf("%s (same as first)\n", ptr);
  8285.        assert(tmpnam(NULL) == ptr);
  8286.        /*  that will overwrite it! */
  8287.        puts(ptr);
  8288.        return(0);
  8289.     }
  8290.  
  8291. dice/tolower,toupper                                    dice/tolower,toupper
  8292.  
  8293.     FUNCTION
  8294.     convert a character into lower or upper case (ANSI)
  8295.  
  8296.     SYNTAX
  8297.     #include <ctype.h>
  8298.     int lc = tolower(c);
  8299.     int uc = toupper(c);
  8300.     int c;
  8301.  
  8302.     || NOTE: These are MACROS if you #include <ctype.h>, subroutine calls
  8303.     || if you do not.
  8304.  
  8305.     DESCRIPTION
  8306.     toupper converts a character from lower to upper case, while tolower
  8307.     does the reverse.  Characters that are not of type upper or lower
  8308.     case (see isupper and islower) are left unchanged.
  8309.  
  8310.     || NOTE: Characters in the -1 to 255 range are valid inputs.
  8311.     || Characters less than -1 or larger than 255 are illegal and the
  8312.     || results will be random.  If you are passing a CHAR, you must cast
  8313.     || it to an UNSIGNED CHAR first. EOF is a valid input an always
  8314.     || returns false (zero).
  8315.  
  8316.     INPUTS
  8317.     int c;            character to be converted
  8318.  
  8319.     RESULTS
  8320.     int lc, uc;        converted character
  8321.  
  8322.     SEE ALSO
  8323.     isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint,
  8324.     ispunct, isspace, isupper, isxdigit
  8325.  
  8326.     EXAMPLE
  8327.     #include <stdio.h>
  8328.     #include <ctype.h>
  8329.     main()
  8330.     {
  8331.     int c;
  8332.  
  8333.         /* Print all 256 characters, showing conversions */
  8334.         for( c=0; c<256; c++) {
  8335.         if( (c & 31) == 0 )    /* 32 per line */
  8336.             printf("\n%02x: ", c);
  8337.         if( isprint( c ) )    /* if printable ... */
  8338.             printf("%c", tolower( c ) );
  8339.         else
  8340.             printf("%c", 127);  /* if not-printable */
  8341.         }
  8342.         printf("\n");
  8343.         return( 0 );
  8344.     }
  8345.  
  8346. dice/ungetc                                                      dice/ungetc
  8347.  
  8348.     FUNCTION
  8349.     push a character back onto a file pointer's input stream (ANSI)
  8350.  
  8351.     SYNTAX
  8352.     #include <stdio.h>
  8353.     int r = ungetc(c, fp);
  8354.     int c;
  8355.     FILE *fp;
  8356.  
  8357.     DESCRIPTION
  8358.     ungetc pushes the specified character back onto the input stream, as
  8359.     if it had not been read.  Only ONE character may be pushed back onto
  8360.     an input stream at a time.  If all went well, the return value r is
  8361.     equal to c.  Else EOF is returned if too many characters were pushed
  8362.     back. Some implementations of C allow multiple characters to be
  8363.      pushed back.  The majority, including DICE, allows only one.
  8364.     ungetc is useful when, in scanning an input stream, you overshoot the
  8365.     'last' character you wanted a particular routine to retrieve.  This
  8366.     routine can push the character back onto the input stream with ungetc
  8367.     so another routine's getc (getchar, fread, fgetc, etc...) will get
  8368.     that character back.
  8369.  
  8370.     INPUTS
  8371.     int c;            character to push back onto input stream
  8372.  
  8373.     FILE *fp;        file pointer stream to push character on to.
  8374.  
  8375.     RESULTS
  8376.     int r;            pushed character (c) if no error, EOF if error
  8377.  
  8378.     SEE ALSO
  8379.     getc, getchar, fread, fgetc
  8380.  
  8381.     EXAMPLE
  8382.     #include <stdio.h>
  8383.     #include <ctype.h>
  8384.     main()
  8385.     {
  8386.        void scan_number();
  8387.        void scan_alpha();
  8388.        puts("Enter nnnaaannn where n=digit a=alpha");
  8389.        puts("Example: 1234abcd99");
  8390.        printf("? ");
  8391.        fflush(stdout);
  8392.        scan_number();  puts("--");
  8393.        scan_alpha();   puts("--");
  8394.        scan_number(); return(0);
  8395.     }
  8396.     static void scan_number()
  8397.     {
  8398.        short c;
  8399.        for (c = getchar(); c >= '0' && c <= '9';
  8400.          c = getchar())
  8401.        {
  8402.            printf("digit: %c\n", c);
  8403.        }
  8404.        if (c != EOF)
  8405.           ungetc(c, stdin);
  8406.     }
  8407.     static void scan_alpha()
  8408.     {
  8409.        short c;
  8410.        for (c = getchar();
  8411.        tolower(c) >= 'a' && tolower(c) <= 'z';
  8412.        c =getchar())
  8413.        {
  8414.           printf("alpha: %c\n", c);
  8415.        }
  8416.           if (c != EOF) ungetc(c, stdin);
  8417.     }
  8418.  
  8419. dice/unlink                                                      dice/unlink
  8420.  
  8421.     FUNCTION
  8422.     delete a file (UNIX)
  8423.  
  8424.     SYNTAX
  8425.     #include <stdio.h>
  8426.     int r = unlink(filename);
  8427.     char *filename;
  8428.  
  8429.     DESCRIPTION
  8430.     unlink deletes a file, equivalent to remove. This call deletes a file
  8431.     from the filesystem.  unlink exists for UNIX compatibility only. Use
  8432.     rmdir to delete a directory if you wish to maintain portability.
  8433.  
  8434.     INPUTS
  8435.     char *filename;     name of file to delete
  8436.  
  8437.     RESULTS
  8438.     int r;            0 if successful, non-zero if error
  8439.  
  8440.     SEE ALSO
  8441.     close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  8442.     rmdir, unlink, write
  8443.  
  8444.     EXAMPLE
  8445.     main()
  8446.     {
  8447.        int r;
  8448.        r = unlink("T:xx");
  8449.        if (r == 0)
  8450.           puts("Deleted T:xx");
  8451.        else
  8452.           puts("Unable to delete t:xx or it does not exist");
  8453.        return(0);
  8454.     }
  8455.  
  8456. dice/wbmain                                                      dice/wbmain
  8457.  
  8458.     FUNCTION
  8459.     main program entry when run from Workbench (DICE)
  8460.  
  8461.     SYNTAX
  8462.     #include <startup.h>
  8463.     int wbmain(struct WBStartup *wbs)
  8464.     {
  8465.         /*    your main code goes here */
  8466.         return(exitcode);
  8467.     }
  8468.  
  8469.     DESCRIPTION
  8470.     The wbmain routine is the entry point called after normal
  8471.     initialization of c.lib and the program environment is done by the
  8472.     startup module (c.o) and _main() routine (in c.lib). wbmain is called
  8473.     when the program is run from the workbench, main is called when the
  8474.     program is run from the CLI.  The exit code is ignored. The standard
  8475.     workbench startup message is passed to wbmain, you can process or
  8476.     ignore this message as you like but should NOT ReplyMsg it.  We
  8477.     repeat, do not ReplyMsg it.  When you return from wbmain or exit out
  8478.     of the program the exit code will automatically deal with the
  8479.     message.
  8480.  
  8481.     SEE ALSO
  8482.     main
  8483.  
  8484.     EXAMPLE
  8485.     /*
  8486.     *  If run from the workbench this program will create a
  8487.     *  file T:XX instead of printing something on the
  8488.     *  console (since there is no console in that case).
  8489.     */
  8490.     #include <stdio.h>
  8491.     int main(int ac, char**av)
  8492.     {
  8493.        puts("This was run from a CLI");
  8494.        return(0);
  8495.     }
  8496.     int wbmain(msg)
  8497.     void *msg;  /* cheat to make the example less complex */
  8498.     {
  8499.        FILE *fi = fopen("T:xx", "w");
  8500.        fprintf(fi, "This was run from the WORKBENCH\n");
  8501.        fclose(fi);
  8502.     }
  8503.  
  8504. dice/write                                                        dice/write
  8505.  
  8506.     FUNCTION
  8507.     write data to a file (UNIX)
  8508.  
  8509.     SYNTAX
  8510.     #include <fcntl.h>
  8511.     int r = write(fd, buf, bytes);
  8512.     int fd;
  8513.     void *buf;
  8514.     int bytes;
  8515.  
  8516.     DESCRIPTION
  8517.     write writes data to a file, starting at the current seek position.
  8518.     It extends the file if necessary, or else writes over existing data.
  8519.     With normal files, write will always return the number of bytes
  8520.     requested and fewer only if an error occurs.  With devices write may
  8521.     or may not return the number of bytes requested depending on the
  8522.     device, though usually it does.
  8523.  
  8524.     || NOTE: Refer to the file_descriptor manual page for general
  8525.     || information. Unlike file pointers and file handles, the file
  8526.     || descriptor is checked for validity and will simply return an error
  8527.     || if illegal.
  8528.  
  8529.     INPUTS
  8530.     int fd;         file descriptor to write to void
  8531.  
  8532.     *buf;            pointer to buffer to write data from
  8533.  
  8534.     int len;        number of bytes to write
  8535.  
  8536.     RESULTS
  8537.     int r;            number of bytes actually written, usually an
  8538.                 error if r !=len.
  8539.  
  8540.     SEE ALSO
  8541.     close, creat, fcntl, fdtofh, ioctl, isatty, lseek, mkdir, open, read,
  8542.     rmdir, unlink
  8543.  
  8544.     EXAMPLE
  8545.     See open for an example
  8546.  
  8547. dice/x.o                                                            dice/x.o
  8548.  
  8549.     FUNCTION
  8550.     autoinit terminating tags (DICE)
  8551.  
  8552.     LIBRARY
  8553.     x.o
  8554.  
  8555.     DESCRIPTION
  8556.     The X.O module is the normally the last object module specified when
  8557.     linking.  DICE has a very unique and elegant system of creating
  8558.     automatic initialization and exit code.  The X.O module terminates
  8559.      these special sections.
  8560.     Autoinit/exit sections work as follows: any object module may define
  8561.     a specially named section which will be linked, in sequence, with
  8562.     other module's sections of the same name.  These sections contain
  8563.     only code and no RTS.  The terminating module X.O adds a single RTS
  8564.     to each section, allowing the base of the section to be called by the
  8565.     startup/exit module (C.O).  Execution propagates through all
  8566.     autoinit/exit routines before hitting the RTS placed in the section
  8567.     by X.O. DICE uses autoinit/exit sections to handle the following
  8568.     things:
  8569.  
  8570.     1) Code to initialize initialized data containing references to other
  8571.        initialized data (i.e.  int a, *b = &a;) when the code must be
  8572.        made residentable.  This precludes the need for the startup code
  8573.        to handle Data-Data 32-bit relocations for resident code.
  8574.  
  8575.     2) Code to open libraries whos base variables are referenced but
  8576.        never declared. _DOSBase and the various floating point libraries
  8577.        are automatically opened in this way whenever library calls to
  8578.        them are made.  This precludes the need for DICE to have massive,
  8579.        complex, and many times unnecessary code in c.lib to handle these
  8580.        situations.
  8581.  
  8582.     3) Code to close libraries that were opened by (2) on exit.
  8583.  
  8584.     4) Entry points for the special __autoinit keyword.
  8585.  
  8586.     SEE ALSO
  8587.     c.o
  8588.  
  8589.     EXAMPLE
  8590.     dlink dlib:c.o myprog.o dlib:x.o -o myprog -v
  8591.